I've been trying to make a diagram using PolyCollection very similar to this one: http://matplotlib.org/examples/mplot3d/polys3d_demo.html
The difference is, I want my code to read all CSV files from a folder and plot the data in them (not random numbers). Each CSV file contains a spectrum, i.e. two columns and a certain number of rows. I want the first row to be my x-values and the second row the corresponding z-values.
I tried this:
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import PolyCollection
fig=plt.figure()
ax = fig.gca(projection='3d')
input_path = 'input'
spectrumfiles = []
verts=[]
for root, dirs, files in os.walk(input_path):
for name in files:
if os.path.splitext(name)[1] == '.CSV' or os.path.splitext(name)[1] == '.csv':
spectrumfiles.append(os.path.join(root,name))
zs = np.arange(len(files))
for name in spectrumfiles:
spectrum = np.loadtxt(name, delimiter=',')
#xs = spectrum[:,0] #I tried this first but then realised that "spectrum
#ys = spectrum[:,1] #already has the needed shape
#verts.append(list(zip(xs,ys)))
verts.append(spectrum)
poly = PolyCollection(verts, facecolors=np.ones(len(verts))) #I'm not too bothered with
poly.set_alpha(0.7) #colours at the moment
ax.add_collection3d(poly, zs=zs, zdir='y')
plt.show()
Now, the diagram I get is empty.
EDIT: here are 4 sample FILES
EDIT2: here are some links to related questions on stackoverflow. - Matplotlib plot pulse propagation in 3d - Waterfall plot python?