1
1
"""
2
- ***********************
3
- Colormaps in Matplotlib
4
- ***********************
2
+ ********************************
3
+ Choosing Colormaps in Matplotlib
4
+ ********************************
5
+
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/custom_colormaps`.
11
+
12
+
5
13
6
- How (and why) to choose a particular colormap.
7
14
8
15
Overview
9
16
========
@@ -268,7 +275,7 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
268
275
# Plot colormap L values. Do separately for each category
269
276
# so each plot can be pretty. To make scatter markers change
270
277
# color along plot:
271
- # http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
278
+ # http://stackoverflow.com/questions/8202605/
272
279
273
280
if cmap_category == 'Sequential' :
274
281
# These colormaps all start at high lightness but we want them
@@ -322,30 +329,31 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
322
329
# plots because the grayscale changes unpredictably through the
323
330
# colormap.
324
331
#
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.
332
+ # Conversion to grayscale is done in many different ways [bw]_. Some of the
333
+ # better ones use a linear combination of the rgb values of a pixel, but
334
+ # weighted according to how we perceive color intensity. A nonlinear method of
335
+ # conversion to grayscale is to use the :math:`L^*` values of the pixels. In
336
+ # general, similar principles apply for this question as they do for presenting
337
+ # one's information perceptually; that is, if a colormap is chosen that is
338
+ # monotonically increasing in :math:`L^*` values, it will print in a reasonable
339
+ # manner to grayscale.
332
340
#
333
341
# With this in mind, we see that the Sequential colormaps have reasonable
334
342
# 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.
343
+ # enough grayscale representations, though some (autumn, spring, summer,
344
+ # winter) have very little grayscale change. If a colormap like this was used
345
+ # in a plot and then the plot was printed to grayscale, a lot of the
346
+ # information may map to the same gray values. The Diverging colormaps mostly
347
+ # vary from darker gray on the outer edges to white in the middle. Some
348
+ # (PuOr and seismic) have noticeably darker gray on one side than the other
349
+ # and therefore are not very symmetric. coolwarm has little range of gray scale
350
+ # and would print to a more uniform plot, losing a lot of detail. Note that
351
+ # overlaid, labeled contours could help differentiate between one side of the
352
+ # colormap vs. the other since color cannot be used once a plot is printed to
353
+ # grayscale. Many of the Qualitative and Miscellaneous colormaps, such as
354
+ # Accent, hsv, and jet, change from darker to lighter and back to darker gray
355
+ # throughout the colormap. This would make it impossible for a viewer to
356
+ # interpret the information in a plot once it is printed in grayscale.
349
357
350
358
mpl .rcParams .update ({'font.size' : 14 })
351
359
@@ -395,13 +403,13 @@ def plot_color_gradients(cmap_category, cmap_list):
395
403
# =========================
396
404
#
397
405
# 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.*,
406
+ # [colorblindness]_). Additionally, there are tools available to convert images
407
+ # to how they look for different types of color vision deficiencies (*e.g.*,
400
408
# [vischeck]_).
401
409
#
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.
410
+ # The most common form of color vision deficiency involves differentiating
411
+ # between red and green. Thus, avoiding colormaps with both red and green will
412
+ # avoid many problems in general.
405
413
#
406
414
#
407
415
# References
@@ -418,3 +426,4 @@ def plot_color_gradients(cmap_category, cmap_list):
418
426
# .. [colorblindness] http://www.color-blindness.com/
419
427
# .. [vischeck] http://www.vischeck.com/vischeck/
420
428
# .. [IBM] https://dx.doi.org/10.1109/VISUAL.1995.480803
429
+ # .. [palettable] https://jiffyclub.github.io/palettable/
0 commit comments