Skip to content

Commit 5d4de7d

Browse files
committed
DOC: link palettable
1 parent 5e20d9b commit 5d4de7d

File tree

3 files changed

+52
-35
lines changed

3 files changed

+52
-35
lines changed

lib/matplotlib/colors.py

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
:doc:`/tutorials/colors/colormapnorms` for more details about data
2727
normalization
2828
29+
More colormaps are available at palettable_
30+
2931
The module also provides functions for checking whether an object can be
3032
interpreted as a color (:func:`is_color_like`), for converting such an object
3133
to an RGBA tuple (:func:`to_rgba`) or to an HTML-like hex string in the
@@ -53,6 +55,9 @@
5355
cycle does not include color.
5456
5557
All string specifications of color, other than "CN", are case-insensitive.
58+
59+
.. _palettable: https://jiffyclub.github.io/palettable/
60+
5661
"""
5762

5863
from collections.abc import Sized

tutorials/colors/colormap-manipulation.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
Creating Colormaps in Matplotlib
44
********************************
55
6-
Creating and manipulating colormaps in Matplotlib is straight-forward
7-
using the class `.ListedColormap` and a Nx4 numpy array of values
8-
between 0 and 1 to represent the RGBA values of the colormap. There
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.
9+
10+
.. _palettable: https://jiffyclub.github.io/palettable/
11+
12+
However, we often want to create or manipulate colormaps in Matplotlib.
13+
This can be done using the class `.ListedColormap` and a Nx4 numpy array of
14+
values between 0 and 1 to represent the RGBA values of the colormap. There
915
is also a `.LinearSegmentedColormap` class that allows colormaps to be
10-
specified with far fewer anchor points defining segments, and linearly
16+
specified with a few anchor points defining segments, and linearly
1117
interpolating between the anchor points.
1218
1319
Getting colormaps and accessing their values

tutorials/colors/colormaps.py

+37-31
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
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
812
Overview
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

350355
mpl.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

Comments
 (0)