1

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()
2
  • 1
    Can you show the rest of your code, I assume that is where the problem is? Commented Jul 15, 2013 at 20:39
  • Consider using subplots instead, and/or using savefig() to dump the plot to a file. This may help you partition the problem into issues which are local to just some interactive backends. Commented Jul 15, 2013 at 20:46

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.