I want to iterate through matplotlib subplots, plotting one trace, tr
in each subplot. However, the output that I currently am getting plots all 8 traces in each subplot. How do I plot just one trace into their own subplots? I suspect it has something to do with my for loop indexing, but I can't seem to determine where this issue lies. Thanks.
The simplified code is below:
traces = glob.glob('*.data')
fig,ax = plt.subplots(nrows=4, ncols=2)
index = 0
for index, ix in enumerate(traces):
tr = obspy.read(traces[index])[0]
*do stuff*
for i in range(4):
for j in range(2):
ax[i, j].plot(time,tr.data, color='k')
index+=1
EDIT: THE CODE BELOW HAS SOLVED THIS QUESTION.
traces = glob.glob('*.data')
fig,axes = plt.subplots(nrows=4, ncols=2)
index = 0
for tr, ax in zip(traces, axes.reshape(-1)):
** do stuff **
tr = obspy.read(traces[index])[0]
ax.plot(time,tr_trim.data, color='k')
ax.set_ylabel("Raw Data")
ax.set_xticks([]);
index +=1
plt.show()