Skip to content

Commit 76b263c

Browse files
committed
DOC: try better math
1 parent c6544d8 commit 76b263c

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

lib/matplotlib/cm.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""
22
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.
33
4-
- See :doc:`/gallery/color/colormap_reference` for a list of builtin
4+
- See :doc:`/gallery/color/colormap_reference` for a list of builtin
55
colormaps.
6-
- See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of
6+
- See :doc:`/tutorials/colors/colormaps` for an in-depth discussion of
77
choosing colormaps.
8-
- See :doc:`/tutorials/colors/colormap-manipulation` for an in-depth
8+
- See :doc:`/tutorials/colors/colormap-manipulation` for an in-depth
99
discussion of how to manipulate colormaps.
1010
1111
"""

tutorials/colors/colormap-manipulation.py

+29-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 ListedColormaps
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,14 @@ def plot_examples(cms):
123123
plot_examples([viridis, newcmp])
124124

125125
##############################################################################
126-
# LinearSegmented colormaps
127-
# =========================
126+
# Creating LinearSegmented colormaps
127+
# ==================================
128128
#
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).
129+
# `.LinearSegmentedColormap` specify colormaps using anchor points
130+
# that between which RGB(A) values are interpolated.
132131
#
133-
# The format to specify these colormaps is a bit complicated to allow
134-
# discontinuities at the anchor points. First, with no discontinuities:
132+
# The format to specify these colormaps allows discontinuities at the anchor
133+
# points. First, with no discontinuities:
135134

136135
cdict = {'red': [[0.0, 0.0, 0.0],
137136
[0.5, 1.0, 1.0],
@@ -161,14 +160,27 @@ def plot_linearmap(cdict):
161160
plot_linearmap(cdict)
162161

163162
#############################################################################
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.
163+
# In order to make a discontinuity at an anchor point, the third column is
164+
# different than the second. The third column is the interpolation value
165+
# to the right of the anchor, and the second column the value to the left.
166+
# The linear interpolation between :math:`x_i=red[i, 0]`` and
167+
# :math:`x_{i+1} = red[i+1, 0]` is
168+
# from :math:`yright_{i} = red[i, 2]` to `yleft_{i+1} = red[i+1, 1]`,
169+
# where the matrix ``red`` is set up as:
170+
# .. math::
171+
#
172+
# \begin{pmatrix}
173+
# \hdotsfor[]{3}
174+
# x_i & yleft_i & yright_i \\
175+
# x_{i+1} & yleft_{i+1} & yright_{i+1} \\
176+
# \hdotsfor[]{3}
177+
# \end{pmatrix}
178+
#
179+
# In the example below there is a discontiuity in red at 0.5. The
180+
# interpolation between 0 and 0.5 goes from 0.3 to 1, and between 0.5 and 1
181+
# it goes from 0.9 to 1. Note that red[0, 1], and red[2, 2] are both
182+
# superfluous to the interpolation because red[0, 1] is the value to the
183+
# left of 0, and red[2, 2] is the value to the right of 1.0.
172184

173185
cdict['red'] = [[0.0, 0.0, 0.3],
174186
[0.5, 1.0, 0.9],

0 commit comments

Comments
 (0)