Skip to content

Commit f58f5f3

Browse files
committed
DOC: move custom_colormap
1 parent 6d2a7bc commit f58f5f3

File tree

5 files changed

+39
-17
lines changed

5 files changed

+39
-17
lines changed

.flake8

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ per-file-ignores =
8686
tutorials/advanced/transforms_tutorial.py: E402, E501
8787
tutorials/colors/colormaps.py: E501
8888
tutorials/colors/colors.py: E402
89+
tutorials/colors/colormap-manipulation.py: E402
8990
tutorials/intermediate/artists.py: E402, E501
9091
tutorials/intermediate/constrainedlayout_guide.py: E402, E501
9192
tutorials/intermediate/gridspec.py: E402, E501
@@ -114,6 +115,7 @@ per-file-ignores =
114115
examples/color/color_demo.py: E402
115116
examples/color/colorbar_basics.py: E402
116117
examples/color/colormap_reference.py: E402
118+
examples/color/custom_cmap.py: E402
117119
examples/color/named_colors.py: E402
118120
examples/event_handling/data_browser.py: E501
119121
examples/event_handling/path_editor.py: E501
@@ -129,7 +131,6 @@ per-file-ignores =
129131
examples/images_contours_and_fields/contourf_demo.py: E402, E501
130132
examples/images_contours_and_fields/contourf_hatching.py: E402
131133
examples/images_contours_and_fields/contourf_log.py: E402
132-
examples/images_contours_and_fields/custom_cmap.py: E402
133134
examples/images_contours_and_fields/demo_bboximage.py: E402
134135
examples/images_contours_and_fields/image_clip_path.py: E402
135136
examples/images_contours_and_fields/image_demo.py: E402

examples/images_contours_and_fields/custom_cmap.py renamed to examples/color/custom_cmap.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Creating a colormap from a list of colors
44
=========================================
55
6+
For more detail on creating and manipulating colormaps see
7+
:doc:`/tutorials/colors/colormap-manipulation`.
8+
69
Creating a :doc:`colormap </tutorials/colors/colormaps>`
710
from a list of colors can be done with the
811
:meth:`~.colors.LinearSegmentedColormap.from_list` method of

lib/matplotlib/cm.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""
22
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.
33
4-
See :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.
5-
See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of colormaps.
4+
- See :doc:`/gallery/color/colormap_reference` for a list of builtin
5+
colormaps.
6+
- See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of
7+
choosing colormaps.
8+
- See :doc:`/tutorials/colors/colormap-manipulation` for an in-depth
9+
discussion of how to manipulate colormaps.
10+
611
"""
712

813
import functools

lib/matplotlib/colors.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66
77
This module includes functions and classes for color specification
88
conversions, and for mapping numbers to colors in a 1-D array of colors called
9-
a colormap. Colormapping typically involves two steps: a data array is first
10-
mapped onto the range 0-1 using an instance of :class:`Normalize` or of a
11-
subclass; then this number in the 0-1 range is mapped to a color using an
12-
instance of a subclass of :class:`Colormap`. Two are provided here:
13-
:class:`LinearSegmentedColormap`, which is used to generate all the built-in
14-
colormap instances, but is also useful for making custom colormaps, and
15-
:class:`ListedColormap`, which is used for generating a custom colormap from a
16-
list of color specifications.
9+
a colormap.
10+
11+
Mapping data onto colors using a colormap typically involves two steps:
12+
a data array is first mapped onto the range 0-1 using a subclass of
13+
:class:`Normalize`, then this number is mapped to a color using
14+
a subclass of :class:`Colormap`. Two are provided here:
15+
:class:`LinearSegmentedColormap`, which uses piecewise-linear interpolation
16+
to define colormaps, and :class:`ListedColormap`, which makes a colormap
17+
from a list of colors.
18+
19+
.. seealso::
20+
21+
:doc:`/tutorials/colors/colormap-manipulation` for examples of how to
22+
make colormaps and
23+
24+
:doc:`/tutorials/colors/colormaps` for a list of built-in colormaps.
25+
26+
:doc:`/tutorials/colors/colormapnorms` for more details about data
27+
normalization
1728
1829
The module also provides functions for checking whether an object can be
1930
interpreted as a color (:func:`is_color_like`), for converting such an object

tutorials/colors/colormap-manipulation.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@
7676
newcolors[:25, :] = pink
7777
newcmp = ListedColormap(newcolors)
7878

79+
7980
def plot_examples(cms):
8081
"""
8182
helper function to plot two colormaps
8283
"""
8384
np.random.seed(19680801)
84-
data = np.random.randn(30,30)
85+
data = np.random.randn(30, 30)
8586

8687
fig, axs = plt.subplots(1, 2, figsize=(6, 3), constrained_layout=True)
87-
for [ax, cm] in zip(axs, cms):
88-
psm = ax.pcolormesh(data, cmap=cm, rasterized=True, vmin=-4, vmax=4)
88+
for [ax, cmap] in zip(axs, cms):
89+
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
8990
fig.colorbar(psm, ax=ax)
9091
plt.show()
9192

@@ -145,6 +146,7 @@ def plot_examples(cms):
145146
[0.5, 0.0, 0.0],
146147
[1.0, 1.0, 1.0]]}
147148

149+
148150
def plot_linearmap(cdict):
149151
newcmp = LinearSegmentedColormap('testCmap', segmentdata=cdict, N=256)
150152
rgba = newcmp(np.linspace(0, 1, 256))
@@ -170,9 +172,9 @@ def plot_linearmap(cdict):
170172
# are both superfluous to the interpolation, which happens between the last
171173
# element of the first anchor and the first element of the second anchor.
172174

173-
cdict['red'] = [[0.0, 0.0, 0.3],
174-
[0.5, 1.0, 0.9],
175-
[1.0, 1.0, 1.0]]
175+
cdict['red'] = [[0.0, 0.0, 0.3],
176+
[0.5, 1.0, 0.9],
177+
[1.0, 1.0, 1.0]]
176178
plot_linearmap(cdict)
177179

178180

0 commit comments

Comments
 (0)