Chris
Chris

Reputation: 31206

How to set line color to orange, and specify line markers

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?

Upvotes: 15

Views: 88957

Answers (3)

Suever
Suever

Reputation: 65430

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

Upvotes: 27

akshay chawla
akshay chawla

Reputation: 74

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/

Upvotes: 3

Warren Weckesser
Warren Weckesser

Reputation: 114811

"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")

Upvotes: 4

Related Questions