Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2D array plotting in matplotlib

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?

like image 529
purpleshift Avatar asked Dec 28 '25 22:12

purpleshift


1 Answers

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.

like image 57
Björn Pollex Avatar answered Dec 30 '25 14:12

Björn Pollex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!