I want to plot multiple lines from a pandas dataframe and setting different options for each line. I would like to do something like
testdataframe=pd.DataFrame(np.arange(12).reshape(4,3))
testdataframe.plot(style=['s-','o-','^-'],color=['b','r','y'],linewidth=[2,1,1])
This will raise some error messages:
-
linewidth is not callable with a list
-
In style I can't use 's' and 'o' or any other alphabetical symbol, when defining colors in a list
Also there is some more stuff which seems weird to me
-
when I add another plot command to the above code
testdataframe[0].plot()
it will plot this line in the same plot, if I add the commandtestdataframe[[0,1]].plot()
it will create a new plot -
If i would call
testdataframe[0].plot(style=['s-','o-','^-'],color=['b','r','y'])
it is fine with a list in style, but not with a list in color
Hope somebody can help, thanks.
Best Answer
You're so close!
You can specify the colors in the styles list:
Also note that the
plot
method can take amatplotlib.axes
object, so you can make multiple calls like this (if you want to):Not really practical in this case, but the concept might come in handy later.