You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/users/colormaps.rst
+96-21Lines changed: 96 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -8,24 +8,37 @@ Choosing Colormaps
8
8
Overview
9
9
========
10
10
11
-
The idea behind choosing a good colormap is to find a good representation in 3D colorspace for your data set. The best colormap for any given data set depends on many things including:
11
+
The idea behind choosing a good colormap is to find a good representation in 3D
12
+
colorspace for your data set. The best colormap for any given data set depends
13
+
on many things including:
12
14
13
15
- Whether representing form or metric data ([Ware]_)
14
16
- Your knowledge of the data set (*e.g.*, is there a critical value from which the other values deviate?)
15
17
- If there is an intuitive color scheme for the parameter you are plotting
16
18
- If there is a standard in the field the audience may be expecting
17
19
18
-
For many applications, a perceptual colormap is the best choice --- one in which equal steps in data are perceived as equal steps in the color space. Researchers have found that the human brain perceives changes in the lightness parameter as changes in the data much better than, for example, changes in hue. Therefore, colormaps which have monotonically increasing lightness through the colormap will be better interpreted by the viewer.
20
+
For many applications, a perceptual colormap is the best choice --- one in which
21
+
equal steps in data are perceived as equal steps in the color space. Researchers
22
+
have found that the human brain perceives changes in the lightness parameter as
23
+
changes in the data much better than, for example, changes in hue. Therefore,
24
+
colormaps which have monotonically increasing lightness through the colormap
25
+
will be better interpreted by the viewer.
19
26
20
-
Color can be represented in 3D space in various ways. One way to represent color is using CIELAB. In CIELAB, color space is represented by lightness, :math:`L^*`; red-green, :math:`a^*`; and yellow-blue, :math:`b^*`. The lightness parameter :math:`L^*` can then be used to learn more about how the matplotlib colormaps will be perceived by viewers.
27
+
Color can be represented in 3D space in various ways. One way to represent color
28
+
is using CIELAB. In CIELAB, color space is represented by lightness,
29
+
:math:`L^*`; red-green, :math:`a^*`; and yellow-blue, :math:`b^*`. The lightness
30
+
parameter :math:`L^*` can then be used to learn more about how the matplotlib
31
+
colormaps will be perceived by viewers.
21
32
22
-
An excellent starting resource for learning about human perception of colormaps is from [IBM]_.
33
+
An excellent starting resource for learning about human perception of colormaps
34
+
is from [IBM]_.
23
35
24
36
25
37
Classes of colormaps
26
38
====================
27
39
28
-
Colormaps are often split into several categories based on their function (see, *e.g.*, [Moreland]_):
40
+
Colormaps are often split into several categories based on their function (see,
41
+
*e.g.*, [Moreland]_):
29
42
30
43
1. Sequential: change in lightness and often saturation of color incrementally, often using a single hue; should be used for representing information that has ordering.
31
44
2. Diverging: change in lightness and possibly saturation of two different colors that meet in the middle at an unsaturated color; should be used when the information being plotted has a critical middle value, such as topography or when the data deviates around zero.
@@ -35,64 +48,127 @@ Colormaps are often split into several categories based on their function (see,
35
48
Lightness of matplotlib colormaps
36
49
=================================
37
50
38
-
Here we examine the lightness values of the matplotlib colormaps. Note that some documentation on the colormaps is available ([list-colormaps]_).
51
+
Here we examine the lightness values of the matplotlib colormaps. Note that some
52
+
documentation on the colormaps is available ([list-colormaps]_).
39
53
40
54
Sequential
41
55
----------
42
56
43
-
For the Sequential plots, the lightness value increases monotonically through the colormaps. This is good. Some of the :math:`L^*` values in the colormaps span from 0 to 100 (binary and the other grayscale), and others start around :math:`L^*=20`. Those that have a smaller range of :math:`L^*` will accordingly have a smaller perceptual range. Note also that the :math:`L^*` function varies amongst the colormaps: some are approximately linear in :math:`L^*` and others are more curved.
57
+
For the Sequential plots, the lightness value increases monotonically through
58
+
the colormaps. This is good. Some of the :math:`L^*` values in the colormaps
59
+
span from 0 to 100 (binary and the other grayscale), and others start around
60
+
:math:`L^*=20`. Those that have a smaller range of :math:`L^*` will accordingly
61
+
have a smaller perceptual range. Note also that the :math:`L^*` function varies
62
+
amongst the colormaps: some are approximately linear in :math:`L^*` and others
63
+
are more curved.
44
64
45
65
Sequential2
46
66
-----------
47
67
48
-
Many of the :math:`L^*` values from the Sequential2 plots are monotonically increasing, but some (autumn, cool, spring, and winter) plateau or even go both up and down in :math:`L^*` space. Others (afmhot, copper, gist_heat, and hot) have kinks in the :math:`L^*` functions. Data that is being represented in a region of the colormap that is at a plateau or kink will lead to a perception of banding of the data in those values in the colormap (see [mycarta-banding]_ for an excellent example of this).
68
+
Many of the :math:`L^*` values from the Sequential2 plots are monotonically
69
+
increasing, but some (autumn, cool, spring, and winter) plateau or even go both
70
+
up and down in :math:`L^*` space. Others (afmhot, copper, gist_heat, and hot)
71
+
have kinks in the :math:`L^*` functions. Data that is being represented in a
72
+
region of the colormap that is at a plateau or kink will lead to a perception of
73
+
banding of the data in those values in the colormap (see [mycarta-banding]_ for
74
+
an excellent example of this).
49
75
50
76
Diverging
51
77
---------
52
78
53
-
For the Diverging maps, we want to have monotonically increasing :math:`L^*` values up to a maximum, which should be close to :math:`L^*=100`, followed by monotonically decreasing :math:`L^*` values. We are looking for approximately equal minimum :math:`L^*` values at opposite ends of the colormap. By these measures, BrBG and RdBu are good options. coolwarm is a good option, but it doesn't span a wide range of :math:`L^*` values (see grayscale section below).
79
+
For the Diverging maps, we want to have monotonically increasing :math:`L^*`
80
+
values up to a maximum, which should be close to :math:`L^*=100`, followed by
81
+
monotonically decreasing :math:`L^*` values. We are looking for approximately
82
+
equal minimum :math:`L^*` values at opposite ends of the colormap. By these
83
+
measures, BrBG and RdBu are good options. coolwarm is a good option, but it
84
+
doesn't span a wide range of :math:`L^*` values (see grayscale section below).
54
85
55
86
Qualitative
56
87
-----------
57
88
58
-
Qualitative colormaps are not aimed at being perceptual maps, but looking at the lightness parameter can verify that for us. The :math:`L^*` values move all over the place throughout the colormap, and are clearly not monotonically increasing. These would not be good options for use as perceptual colormaps.
89
+
Qualitative colormaps are not aimed at being perceptual maps, but looking at the
90
+
lightness parameter can verify that for us. The :math:`L^*` values move all over
91
+
the place throughout the colormap, and are clearly not monotonically increasing.
92
+
These would not be good options for use as perceptual colormaps.
59
93
60
94
Miscellaneous
61
95
-------------
62
96
63
-
Some of the miscellaneous colormaps have particular uses they have been created for. For example, gist_earth, ocean, and terrain all seem to be created for plotting topography (green/brown) and water depths (blue) together. We would expect to see a divergence in these colormaps, then, but multiple kinks may not be ideal, such as in gist_earth and terrain. CMRmap was created to convert well to grayscale, though it does appear to have some small kinks in :math:`L^*`. cubehelix was created to vary smoothly in both lightness and hue, but appears to have a small hump in the green hue area.
97
+
Some of the miscellaneous colormaps have particular uses they have been created
98
+
for. For example, gist_earth, ocean, and terrain all seem to be created for
99
+
plotting topography (green/brown) and water depths (blue) together. We would
100
+
expect to see a divergence in these colormaps, then, but multiple kinks may not
101
+
be ideal, such as in gist_earth and terrain. CMRmap was created to convert well
102
+
to grayscale, though it does appear to have some small kinks in :math:`L^*`.
103
+
cubehelix was created to vary smoothly in both lightness and hue, but appears to
104
+
have a small hump in the green hue area.
64
105
65
-
The often-used jet colormap is included in this set of colormaps. We can see that the :math:`L^*` values vary widely throughout the colormap, making it a poor choice for representing data for viewers to see perceptually. See an extension on this idea at [mycarta-jet]_.
106
+
The often-used jet colormap is included in this set of colormaps. We can see
107
+
that the :math:`L^*` values vary widely throughout the colormap, making it a
108
+
poor choice for representing data for viewers to see perceptually. See an
109
+
extension on this idea at [mycarta-jet]_.
66
110
67
111
.. plot:: users/plotting/colormaps/lightness.py
68
112
69
113
70
114
:math:`L^*` function
71
115
====================
72
116
73
-
There are multiple approaches to finding the best function for :math:`L^*` across a colormap. Linear gives reasonable results (*e.g.*, [mycarta-banding]_, [mycarta-lablinear]_). However, the Weber-Fechner law, and more generally and recently, Stevens' Law, indicates that a logarithmic or geometric relationship might be better (see effort on this front at [mycarta-cubelaw]_).
117
+
There are multiple approaches to finding the best function for :math:`L^*`
118
+
across a colormap. Linear gives reasonable results (*e.g.*, [mycarta-banding]_,
119
+
[mycarta-lablinear]_). However, the Weber-Fechner law, and more generally and
120
+
recently, Stevens' Law, indicates that a logarithmic or geometric relationship
121
+
might be better (see effort on this front at [mycarta-cubelaw]_).
74
122
75
123
.. plot:: users/plotting/colormaps/Lfunction.py
76
124
77
125
78
126
Grayscale conversion
79
127
====================
80
128
81
-
Conversion to grayscale is important to pay attention to for printing publications that have color plots. If this is not paid attention to ahead of time, your readers may end up with indecipherable plots because the grayscale changes unpredictably through the colormap.
82
-
83
-
Conversion to grayscale is done in many different ways [bw]_. Some of the better ones use a linear combination of the rgb values of a pixel, but weighted according to how we perceive color intensity. A nonlinear method of conversion to grayscale is to use the :math:`L^*` values of the pixels. In general, similar principles apply for this question as they do for presenting one's information perceptually; that is, if a colormap is chosen that has monotonically increasing in :math:`L^*` values, it will print in a reasonable manner to grayscale.
84
-
85
-
With this in mind, we see that the Sequential colormaps have reasonable representations in grayscale. Some of the Sequential2 colormaps have decent enough grayscale representations, though some (autumn, spring, summer, winter) have very little grayscale change. If a colormap like this was used in a plot and then the plot was printed to grayscale, a lot of the information may map to the same gray values. The Diverging colormaps mostly vary from darker gray on the outer edges to white in the middle. Some (PuOr and seismic) have noticably darker gray on one side than the other and therefore are not very symmetric. coolwarm has little range of gray scale and would print to a more uniform plot, losing a lot of detail. Note that overlaid, labeled contours could help differentiate between one side of the colormap vs. the other since color cannot be used once a plot is printed to grayscale. Many of the Qualitative and Miscellaneous colormaps, such as Accent, hsv, and jet, change from darker to lighter and back to darker gray throughout the colormap. This would make it impossible for a viewer to interpret the information in a plot once it is printed in grayscale.
129
+
Conversion to grayscale is important to pay attention to for printing
130
+
publications that have color plots. If this is not paid attention to ahead of
131
+
time, your readers may end up with indecipherable plots because the grayscale
132
+
changes unpredictably through the colormap.
133
+
134
+
Conversion to grayscale is done in many different ways [bw]_. Some of the better
135
+
ones use a linear combination of the rgb values of a pixel, but weighted
136
+
according to how we perceive color intensity. A nonlinear method of conversion
137
+
to grayscale is to use the :math:`L^*` values of the pixels. In general, similar
138
+
principles apply for this question as they do for presenting one's information
139
+
perceptually; that is, if a colormap is chosen that has monotonically increasing
140
+
in :math:`L^*` values, it will print in a reasonable manner to grayscale.
141
+
142
+
With this in mind, we see that the Sequential colormaps have reasonable
143
+
representations in grayscale. Some of the Sequential2 colormaps have decent
144
+
enough grayscale representations, though some (autumn, spring, summer, winter)
145
+
have very little grayscale change. If a colormap like this was used in a plot
146
+
and then the plot was printed to grayscale, a lot of the information may map to
147
+
the same gray values. The Diverging colormaps mostly vary from darker gray on
148
+
the outer edges to white in the middle. Some (PuOr and seismic) have noticably
149
+
darker gray on one side than the other and therefore are not very symmetric.
150
+
coolwarm has little range of gray scale and would print to a more uniform plot,
151
+
losing a lot of detail. Note that overlaid, labeled contours could help
152
+
differentiate between one side of the colormap vs. the other since color cannot
153
+
be used once a plot is printed to grayscale. Many of the Qualitative and
154
+
Miscellaneous colormaps, such as Accent, hsv, and jet, change from darker to
155
+
lighter and back to darker gray throughout the colormap. This would make it
156
+
impossible for a viewer to interpret the information in a plot once it is
157
+
printed in grayscale.
86
158
87
159
.. plot:: users/plotting/colormaps/grayscale.py
88
160
89
161
90
162
Color vision deficiencies
91
163
=========================
92
164
93
-
There is a lot of information available about color blindness available (*e.g.*, [colorblindness]_). Additionally, there are tools available to convert images to how they look for different types of color vision deficiencies (*e.g.*, [asp]_).
165
+
There is a lot of information available about color blindness available (*e.g.*,
166
+
[colorblindness]_). Additionally, there are tools available to convert images to
167
+
how they look for different types of color vision deficiencies (*e.g.*, [asp]_).
94
168
95
-
The most common form of color vision deficiency involves differentiating between red and green. Thus, avoiding colormaps with both red and green will avoid many problems in general.
169
+
The most common form of color vision deficiency involves differentiating between
170
+
red and green. Thus, avoiding colormaps with both red and green will avoid many
0 commit comments