Skip to content

Commit 84e9f62

Browse files
committed
DOC: try better math
1 parent c6544d8 commit 84e9f62

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed

lib/matplotlib/cm.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
"""
22
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.
33
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.
4+
.. seealso::
5+
6+
:doc:`/gallery/color/colormap_reference` for a list of builtin
7+
colormaps.
8+
9+
:doc:`/tutorials/colors/colormap-manipulation` for examples of how to
10+
make colormaps and
11+
12+
:doc:`/tutorials/colors/colormaps` an in-depth discussion of
13+
choosing colormaps.
14+
15+
:doc:`/tutorials/colors/colormapnorms` for more details about data
16+
normalization
17+
1018
1119
"""
1220

tutorials/colors/colormap-manipulation.py

+30-17
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
print('viridis(np.linspace(0, 1, 15))', viridis(np.linspace(0, 1, 15)))
5656

5757
##############################################################################
58-
# Creating a new ListedColormap
59-
# =============================
58+
# Creating Listed colormaps
59+
# =========================
6060
#
6161
# This is essential the inverse operation of the above where we supply a
6262
# Nx4 numpy array with all values between 0 and 1,
@@ -123,15 +123,19 @@ def plot_examples(cms):
123123
plot_examples([viridis, newcmp])
124124

125125
##############################################################################
126-
# LinearSegmented colormaps
127-
# =========================
126+
# Creating LinearSegmented colormaps
127+
# ==================================
128+
#
129+
# `.LinearSegmentedColormap` class specifies colormaps using anchor points
130+
# between which RGB(A) values are interpolated.
128131
#
129-
# `.LinearSegmentedColormap` have an alternate way to specify colormaps that
130-
# specify anchor points for linear ramps for each of RGB, and optionally, alpha
131-
# (RGBA).
132+
# The format to specify these colormaps allows discontinuities at the anchor
133+
# points. Each anchor point is specified as a row in a matrix of the
134+
# form ``[x[i] yleft[i] yright[i]]``, where ``x[i]`` is the anchor, and
135+
# ``yleft[i]`` and ``yright[i]`` are the values of the color on either
136+
# side of the anchor point.
132137
#
133-
# The format to specify these colormaps is a bit complicated to allow
134-
# discontinuities at the anchor points. First, with no discontinuities:
138+
# If there are no discontinuities, then ``yleft[i]=yright[i]``:
135139

136140
cdict = {'red': [[0.0, 0.0, 0.0],
137141
[0.5, 1.0, 1.0],
@@ -161,14 +165,23 @@ def plot_linearmap(cdict):
161165
plot_linearmap(cdict)
162166

163167
#############################################################################
164-
# However, consider the case where the third column is different than the
165-
# second. The linear interpolation between red[i, 0] and red[i+1, 0] is
166-
# from red[i, 2] to red[i+1, 1]. This format allows us to have
167-
# discontinuities in the colormap at the anchor points; in this case
168-
# between 0 and 0.5, the linear interpolation goes from 0.3 to 1, and
169-
# between 0.5 and 1 it goes from 0.9 to 1. Note that red[0, 1], and red[2, 2]
170-
# are both superfluous to the interpolation, which happens between the last
171-
# element of the first anchor and the first element of the second anchor.
168+
# In order to make a discontinuity at an anchor point, the third column is
169+
# different than the second. The matrix for each of "red", "green", "blue",
170+
# and optionally "alpha" is set up as::
171+
#
172+
# cdict['red'] = [...
173+
# [x[i] yleft[i] yright[i]],
174+
# [x[i+1] yleft[i+1] yright[i+1]],
175+
# ...]
176+
#
177+
# and for values passed to the colormap between ``x[i]`` and ``x[i+1]``,
178+
# the interpolation is between ``yright[i]`` and ``yleft[i+1]``.
179+
#
180+
# In the example below there is a discontiuity in red at 0.5. The
181+
# interpolation between 0 and 0.5 goes from 0.3 to 1, and between 0.5 and 1
182+
# it goes from 0.9 to 1. Note that red[0, 1], and red[2, 2] are both
183+
# superfluous to the interpolation because red[0, 1] is the value to the
184+
# left of 0, and red[2, 2] is the value to the right of 1.0.
172185

173186
cdict['red'] = [[0.0, 0.0, 0.3],
174187
[0.5, 1.0, 0.9],

0 commit comments

Comments
 (0)