11"""
2- ***********************
3- Colormaps in Matplotlib
4- ***********************
2+ ********************************
3+ Choosing Colormaps in Matplotlib
4+ ********************************
55
6- How (and why) to choose a particular colormap.
6+ Matplotlib has a number of built-in colormaps accessible via
7+ `.matplotlib.cm.get_cmap`. There are also external libraries like
8+ [palettable]_ that have many extra colormaps. Here we briefly discuss
9+ how to choose between the many options. For help on creating your
10+ own colormaps, see :doc:`/tutorials/colors/colormap-manipulation`.
711
812Overview
913========
@@ -268,7 +272,7 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
268272 # Plot colormap L values. Do separately for each category
269273 # so each plot can be pretty. To make scatter markers change
270274 # color along plot:
271- # http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
275+ # http://stackoverflow.com/questions/8202605/
272276
273277 if cmap_category == 'Sequential' :
274278 # These colormaps all start at high lightness but we want them
@@ -322,30 +326,31 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
322326# plots because the grayscale changes unpredictably through the
323327# colormap.
324328#
325- # Conversion to grayscale is done in many different ways [bw]_. Some of the better
326- # ones use a linear combination of the rgb values of a pixel, but weighted
327- # according to how we perceive color intensity. A nonlinear method of conversion
328- # to grayscale is to use the :math:`L^*` values of the pixels. In general, similar
329- # principles apply for this question as they do for presenting one's information
330- # perceptually; that is, if a colormap is chosen that is monotonically increasing
331- # in :math:`L^*` values, it will print in a reasonable manner to grayscale.
329+ # Conversion to grayscale is done in many different ways [bw]_. Some of the
330+ # better ones use a linear combination of the rgb values of a pixel, but
331+ # weighted according to how we perceive color intensity. A nonlinear method of
332+ # conversion to grayscale is to use the :math:`L^*` values of the pixels. In
333+ # general, similar principles apply for this question as they do for presenting
334+ # one's information perceptually; that is, if a colormap is chosen that is
335+ # monotonically increasing in :math:`L^*` values, it will print in a reasonable
336+ # manner to grayscale.
332337#
333338# With this in mind, we see that the Sequential colormaps have reasonable
334339# representations in grayscale. Some of the Sequential2 colormaps have decent
335- # enough grayscale representations, though some (autumn, spring, summer, winter)
336- # have very little grayscale change. If a colormap like this was used in a plot
337- # and then the plot was printed to grayscale, a lot of the information may map to
338- # the same gray values. The Diverging colormaps mostly vary from darker gray on
339- # the outer edges to white in the middle. Some (PuOr and seismic) have noticeably
340- # darker gray on one side than the other and therefore are not very symmetric.
341- # coolwarm has little range of gray scale and would print to a more uniform plot,
342- # losing a lot of detail. Note that overlaid, labeled contours could help
343- # differentiate between one side of the colormap vs. the other since color cannot
344- # be used once a plot is printed to grayscale. Many of the Qualitative and
345- # Miscellaneous colormaps, such as Accent, hsv, and jet, change from darker to
346- # lighter and back to darker gray throughout the colormap. This would make it
347- # impossible for a viewer to interpret the information in a plot once it is
348- # printed in grayscale.
340+ # enough grayscale representations, though some (autumn, spring, summer,
341+ # winter) have very little grayscale change. If a colormap like this was used
342+ # in a plot and then the plot was printed to grayscale, a lot of the
343+ # information may map to the same gray values. The Diverging colormaps mostly
344+ # vary from darker gray on the outer edges to white in the middle. Some
345+ # (PuOr and seismic) have noticeably darker gray on one side than the other
346+ # and therefore are not very symmetric. coolwarm has little range of gray scale
347+ # and would print to a more uniform plot, losing a lot of detail. Note that
348+ # overlaid, labeled contours could help differentiate between one side of the
349+ # colormap vs. the other since color cannot be used once a plot is printed to
350+ # grayscale. Many of the Qualitative and Miscellaneous colormaps, such as
351+ # Accent, hsv, and jet, change from darker to lighter and back to darker gray
352+ # throughout the colormap. This would make it impossible for a viewer to
353+ # interpret the information in a plot once it is printed in grayscale.
349354
350355mpl .rcParams .update ({'font.size' : 14 })
351356
@@ -395,13 +400,13 @@ def plot_color_gradients(cmap_category, cmap_list):
395400# =========================
396401#
397402# There is a lot of information available about color blindness (*e.g.*,
398- # [colorblindness]_). Additionally, there are tools available to convert images to
399- # how they look for different types of color vision deficiencies (*e.g.*,
403+ # [colorblindness]_). Additionally, there are tools available to convert images
404+ # to how they look for different types of color vision deficiencies (*e.g.*,
400405# [vischeck]_).
401406#
402- # The most common form of color vision deficiency involves differentiating between
403- # red and green. Thus, avoiding colormaps with both red and green will avoid many
404- # problems in general.
407+ # The most common form of color vision deficiency involves differentiating
408+ # between red and green. Thus, avoiding colormaps with both red and green will
409+ # avoid many problems in general.
405410#
406411#
407412# References
@@ -418,3 +423,4 @@ def plot_color_gradients(cmap_category, cmap_list):
418423# .. [colorblindness] http://www.color-blindness.com/
419424# .. [vischeck] http://www.vischeck.com/vischeck/
420425# .. [IBM] https://dx.doi.org/10.1109/VISUAL.1995.480803
426+ # .. [palettable] https://jiffyclub.github.io/palettable/
0 commit comments