3

I was trying to plot a 2D array vs a 1D array with pyplot. I can do that with no problems and columns in the 2D array are treated like two different sets of Y datas, which is what i want. What i don't know is how to specify a different color for every column in the 2d array. if i use pyplot.plot(1darray, 2darray, "r-") every column in 2d array is plotted red for example. Should i modify the standard color map or is there a smarter way?

2
  • 1
    Have you tried leaving out the color specification, and just let matplotlib choose the colors? I mean this: pyplot.plot(1darray, 2darray, "-") Commented Mar 25, 2011 at 8:30
  • 1
    yes, but i want to choose the colors for the different columns. Commented Mar 25, 2011 at 12:19

1 Answer 1

1

If you want to use custom colors for each column, then the best approach is to plot each column explicitly using a loop:

for column, colcolor in zip(2darray, colors):
    pyplot.plot(2darray, column, "-", color=colcolor)

You may have to use 2darray.T, I'm not sure, and I can't check right now.

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

1 Comment

no, normally you should transpose them but the cycle pick up the first element anyway

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.