Send
Close Add comments:
(status displays here)
Got it! This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website. Note: This appears on each machine/browser from which this site is accessed.
Matplotlib: Color models
1. Matplotlib: Color models
This page looks at color models in general and then color models as used by Python and libraries, particularly matplotlib.
2. Goal of scalability
A goal in any graphic is that the graphic be scalable in such a way that (preferably) one and only one parameter in the program needs to be changed to rescale the graphic. This involves finding any dependencies and defining them in terms of that one parameter.
3. The RGB color model
There are many models for representing color.
We will look at color as seen by humans in terms of the additive light model and the subtractive print model.
When presenting graphics using color, one must always keep in mind how other humans and humans in general see color, and not how you see color, which colors you prefer, etc.
4. Human eye
Many humans have trouble distinguishing red and blue when juxtaposed. These colors (e.g., ultra-violet and infra-red) are at opposite ends of the color spectrum so dispersion of light in the eye is at a maximum.
Remember, people see different colors differently. In general, for presentation purposes, try to use a high contrast between background and foreground (e.g., text) colors.
5. RGB additive color model
(nothing) = Black
Red + Green = Yellow
Green + Blue = Cyan
Blue + Red = Magenta
Red + Green + Blue = White
The
RGB (Red Green Blue) color model is an additive light-based color model that works well for screen displays. In a light-based model, all colors (i.e., red, white, and blue) make white. The background of the screen is assumed to be black and colors add to the color seen.
The additive light model assumes that the absence of color is black and that adding all colors, as in light, results in the human eye seeing white.
6. CMYK subtractive color model
(nothing) = White
Cyan + Magenta = Blue
Magenta + Yellow = Red
Yellow + Cyan = Green
Cyan + Magenta + Yellow = Black
The
CMYK (Cyan Magenta Yellow Black) color model is a subtractive pigment-based color model that works well for printed material. The background of the paper is assumed to be white and colors subtract from the color seen (by absorbing color that would otherwise be reflected).
Since, in practice, the combination of cyan, magenta, and yellow make a muddy brown rather than black, black is added in the printing process.
CMYK values go from
0.0 to
1.0 though sometimes they are specified from
0 to
100 and must be, therefore, each divided by
100.0 to map them into the range
0.0 to
1.0
7. Conversion
The conversion between CMYK and RGB can be approximated using the above model. Here is one way using the CMYK as (C, M, Y, K) each from
0.0 to
1.0 to map to RGB as (R, G, B) each from
0 to
255.
R = ( 1 - ( C * ( 1 - K ) + K )) * 255
G = ( 1 - ( M * ( 1 - K ) + K )) * 255
B = ( 1 - ( Y * ( 1 - K ) + K )) * 255
8. 24 bit color
A
24 bit
RGB additive light model uses
1 byte (8 bits) for red,
1 byte (8 bits) for green, and
1 byte (8 bits) for blue.
(
256 values)*(
256 values)*(
256 values) provides about
16.7 million colors.
This is called a "
true color" model since the human eye cannot distinguish between small changes in the colors.
RGB values go from
0 to
255 as they are for a byte-oriented architecture.
How many values can be represented with 8 bits?
9. Hex numbers
For review, here are the 16 base 16 (hexadecimal) numbers from
0 to
15.
0 1 2 3 4 5 6 7
8 9 A B C D E F
10. HTML 24-bit color
HTML uses an RGB color model. Here are some HTML color literals.
#000000 is black.
#FF0000 is (pure) red .
#00FF00 is (pure) green .
#0000FF is (pure) blue .
#00FFFF is (pure) cyan .
#FF00FF is (pure) magenta .
#FFFF00 is (pure) yellow .
#FFFFFF is white.
Write the HTML hexadecimal literals for red, green, blue, and white. Hint: Black is #000000.
11. Shades of gray
In the RGB color model, shades of gray go from black to white. Here are some values from black to white in hex.
#000000
#333333
#666666
#999999
#CCCCCC
#FFFFFF
Here is the Python code [#1]
Here is the output of the Python code.
12. Pure colors
Here are
8 pure colors from the above program.
13. Light colors
Here are the above colors in a lighter version as I like to use for background colors.
14. Dark colors
Here are the above colors in a darker version as I like to use for foreground colors (borders, font, etc.) to go along with the lighter colors as background.
15. End of page