Matplotlib: how to set line color to orange, and specify line markers?

Question:

I have a situation where I have many lines that I am plotting in pyplot.

They are grouped by color, and within each color, I plot according to plot style–so the circles, dashes, etc.

My plot styling is:

plt.plot(x,y1,'b')
plt.plot(x,y2,'bs')
plt.plot(x,y3,'b--')

And then I repeat for various colors. However, I am running into trouble with orange. When I plot with orange, I get an error because pyplot wants to plot with circles instead of the color orange! Here is an example:

plt.plot(x,z1,'o')
plt.plot(x,z2,'os')
plt.plot(x,z3,'o--')

This fails because 'os' is being parsed as two formatting instructions, rather than a color and the format: squares.

How do I work around this in order to plot the orange lines?

Asked By: Chris

||

Answers:

That is because the character 'o' is not a pre-defined single-letter color code. You will instead need to use either the RGB value or the string 'orange' as your color specification (see below).

plt.plot(x, z3, '--', color='orange')           % String colorspec
plt.plot(x, z3, '--', color='#FFA500')          % Hex colorspec
plt.plot(x, z3, '--', color=[1.0, 0.5, 0.25])   % RGB colorspec
Answered By: Suever

"o" is not one of the available color codes.

An alternative to plt.plot(x,z3,'o--') is, for example,

plt.plot(x, z3, '--', color="orange")
Answered By: Warren Weckesser

Use HTML colour codes to specify the colour of your plot. Something along the lines of ->

plt.plot(x,y,'o',color='#F39C12')

This plots x,y with orange circles.
orange circles look pretty with sinusiods

Edit: You can nitpick your color at http://htmlcolorcodes.com/

Answered By: akshay chawla
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.