Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: how to plot with custom colors and symbols

How can I use colors that have a long name and custom markers in Pandas?

With standard colors I would do:

df.plot(style = 'ro')

but I cannot do:

df.plot(style = 'lightgreeno')

I tried:

df.plot(color = 'lightgreen', style = 'o')

but I get:

ValueError: Cannot pass 'style' string with a color symbol and 'color' keyword argument. Please use one or the other or pass 'style' without a color symbol

any ideas?

like image 509
Fra Avatar asked Apr 29 '15 02:04

Fra


People also ask

How do I specify colors in Matplotlib?

The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.

How do I add a label to a plot in pandas?

You can set the labels on that object. Or, more succinctly: ax. set(xlabel="x label", ylabel="y label") . Alternatively, the index x-axis label is automatically set to the Index name, if it has one.


1 Answers

style wraps color and marker and linestyle together. As soon as you specify one of those explicitly, you need to be explicit about any of them. An example from the plot documentation:

plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12).

so in your line change style to marker :

df.plot(color = 'lightgreen', marker = 'o')
like image 53
cphlewis Avatar answered Nov 11 '22 19:11

cphlewis