Saturday, November 04, 2017

3D Rotative Graph from a CSV file using Python

There are several modules in Python to create different types of graphs. "The Python Graph Gallery" brings together several examples, as rotating 3D chart, created from a data file in CSV format. The next code, from Yan Holtz, save 70 PNG images in the "filename" folder. Then you just need to convert them to GIF format using, for example, gifmaker.meThis code can easily be adapted to read EEG data files.

# library
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

# Get the data (csv file is hosted on the web)
url = ''
data = pd.read_csv(url)

# Transform it to a long format

# And transform the old column name in something numeric

# We are going to do 20 plots, for 20 different angles
for angle in range(70,210,2):

   # Make the plot
   fig = plt.figure()
   ax = fig.gca(projection='3d')
   ax.plot_trisurf(df['Y'], df['X'], df['Z'],, linewidth=0.2)

   # Set the angle of the camera

   # Save it
   plt.savefig(filename, dpi=96)

For more information about BCI/EEG press here.

No comments:

Post a Comment