Answer a 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?

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
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐