0

So when I use pyplot I know how to use the colours blue and red dots, 'bo' and 'ro' respectively. However I cannot find the respective colour codes for orange, yellow, green, indigo and violet (Yup I'm modelling a rainbow). I have been trying to find these colours over the internet with no luck. Can someone please give me a link to these colour codes or list them here please.

Also I don't want to produce dots but coloured lines.

user3065619
  • 107
  • 1
  • 4
  • 9

2 Answers2

1

You can use those color codes, an RGB tuple, or you can also use hex colors, which are very easy and customizable (HTML hex color charts are widely available on the web).

Here's the documentation on the color codes: http://matplotlib.org/api/colors_api.html

What 'bo' and 'ro' actually are are two concatenated strings: a one-character string representing the color plus a one-character string representing the line style, in this case, a dot. See http://matplotlib.org/users/pyplot_tutorial.html, where it explains that if you use 'b-' instead of 'bo', it means a blue line instead of a blue dot.

This means that you can use any of the color codes in the colors api link above, followed by an o. For example, a green dot should be 'go'.

If the one-character strings for colors don't suit your needs, you can follow another format:

plot(x, y, color='green', linestyle='dashed', marker='o').

You can insert color names, hex codes, or RGB tuples in the color field.

pique
  • 96
  • 1
  • 1
  • 6
  • I can't find the same format colour codes. I can't even find 'ro' or 'bo' on that link. – user3065619 Dec 07 '13 at 11:01
  • Did you try these? They should work. I didn't find anything specifically on 'bo' or 'ro', but it might help if you share what you've already done, for more context. – pique Dec 07 '13 at 11:21
  • hi pique. I want to get the colour codes for the remaining colours (orange, indigo and violet). I already know of 'r' and 'b' and 'y' and 'g'. – user3065619 Dec 07 '13 at 11:29
  • Updated to explain line styles. – pique Dec 07 '13 at 11:30
  • okay so do I just copy these colour codes in capslock enclosed with apostrophes? I get an error when I copy that colour code :S – user3065619 Dec 07 '13 at 11:32
  • You can add 'o' to anything that the colors_api link says is a valid color. According to the pyplotlib docs, you should be able to use 'orangeo' or '#FFA500o' for orange. – pique Dec 07 '13 at 11:33
  • Yeah, but add on the symbol standing for the line style you want at the end, before the closing single quote. '#FFA500o' for an orange dot, '#FFA500-' for an orange line. – pique Dec 07 '13 at 11:35
  • I get this error though: ValueError: Unrecognized character # in format string – user3065619 Dec 07 '13 at 11:36
  • Try taking out the # from the string. Although the pyplot docs indicate it should be included. Here: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot, search for "color" in your browser – pique Dec 07 '13 at 11:39
  • I tried adding it and removing it. In fact even using 'orangeo' gives me an error. – user3065619 Dec 07 '13 at 11:41
  • Sorry, the pyplot docs were misleading. I added a solution above that should work for you though. Basically, instead of the 'bo' string, you would use color='blue', marker='o'. – pique Dec 07 '13 at 11:48
1

You can define only a few built-in colors by a single letter (in your case, 'b' and 'r' specifies the color, 'o' specifies the dot type, not the color). You can plot blue lines using 'b-', dotted blue lines using 'b.-' and so on.

The built-in colors are: b: blue g: green r: red c: cyan m: magenta y: yellow k: black w: white

Every other color can be given through their color codes.

See all color formats in the docs here.

Community
  • 1
  • 1
leeladam
  • 1,748
  • 10
  • 15