Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22017fa

Browse filesBrowse files
committed
DOC: link palettable
1 parent 5e20d9b commit 22017fa
Copy full SHA for 22017fa

File tree

Expand file treeCollapse file tree

3 files changed

+55
-35
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+55
-35
lines changed

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+5Lines changed: 5 additions & 0 deletions
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

Copy file name to clipboardExpand all lines: tutorials/colors/colormap-manipulation.py
+10-4Lines changed: 10 additions & 4 deletions
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

Copy file name to clipboardExpand all lines: tutorials/colors/colormaps.py
+40-31Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
"""
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+
513
6-
How (and why) to choose a particular colormap.
714
815
Overview
916
========
@@ -268,7 +275,7 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
268275
# Plot colormap L values. Do separately for each category
269276
# so each plot can be pretty. To make scatter markers change
270277
# 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/
272279

273280
if cmap_category == 'Sequential':
274281
# These colormaps all start at high lightness but we want them
@@ -322,30 +329,31 @@ def plot_color_gradients(cmap_category, cmap_list, nrows):
322329
# plots because the grayscale changes unpredictably through the
323330
# colormap.
324331
#
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.
332340
#
333341
# With this in mind, we see that the Sequential colormaps have reasonable
334342
# 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.
349357

350358
mpl.rcParams.update({'font.size': 14})
351359

@@ -395,13 +403,13 @@ def plot_color_gradients(cmap_category, cmap_list):
395403
# =========================
396404
#
397405
# 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.*,
400408
# [vischeck]_).
401409
#
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.
405413
#
406414
#
407415
# References
@@ -418,3 +426,4 @@ def plot_color_gradients(cmap_category, cmap_list):
418426
# .. [colorblindness] http://www.color-blindness.com/
419427
# .. [vischeck] http://www.vischeck.com/vischeck/
420428
# .. [IBM] https://dx.doi.org/10.1109/VISUAL.1995.480803
429+
# .. [palettable] https://jiffyclub.github.io/palettable/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.