Reputation: 435
I have imported and processed multiple datasets in numpy/python- from the datasets I can created several arrays with the data - for the sake of argument let's say 3 arrays; A B C now I want to plot the data:
currently I chose each array, and plot the data - this is fine, but when I have 18 arrays, then it becomes at least non efficient
so I tried, to create a list and iterate through each array:
allarrays = [A, B, C] #where A, B and C are arrays
for array in allarrays:
pylab.figure()
.......
.......
.......
pylab.show()
with that A plots fine, but B comes empty, and then it stops
I imaging that doing a list of arrays is probably not the proper way, but cannot seem to figure it out any ideas welcome
Dimitris
the actual code as requested - the arrays (A12, A23 etc have been created in a previous step)
enter code here
allarrays = [A12, A23]#, A34, A45, B12, B23, B34, B45, C12, C23, C34, C45,]
size = len(A12)
for array in allarrays:
to_plot=np.zeros(shape=(size, 5))
plt.figure() # so each figure is a fresh start
for i in range(0, size, n):
to_plot=np.array(array, dtype='float')
plt.subplot(2, 2, 1)
plt.xlim(0.1, 1000)
plt.xlabel('frequency')
plt.ylabel('phase(mrad)')
plt.semilogx(to_plot[i:i + n, 0], to_plot[i:i + n, 2], 'o-', color=next(colors))
plt.grid(True)
plt.hold(True)
plt.subplot(2, 2, 2)
plt.xlim(0.1, 1000)
plt.xlabel('frequency')
plt.ylabel('imag(S/m)')
plt.loglog(to_plot[i:i + n, 0], to_plot[i:i + n, 3], 'o-', color=next(colors1))
plt.grid(True)
plt.hold(True)
plt.tight_layout()
plt.show()
Upvotes: 1
Views: 1186
Reputation: 435
My mistake, and as #debianplebian suggested the problem was with the followup code - I actually needed to define colors within the high level loop - I failed to do so and when the 2nd iteration reached the color it stuck
Upvotes: 1