Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4302477

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

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

lib/matplotlib/cm.py

Lines changed: 3 additions & 3 deletions
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

Lines changed: 31 additions & 17 deletions
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,18 @@ 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+
# 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. 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 fo the anchor point. If there are no discontinuities, then
137+
# ``yleft[i]=yright[i]``:
135138

136139
cdict = {'red': [[0.0, 0.0, 0.0],
137140
[0.5, 1.0, 1.0],
@@ -161,14 +164,25 @@ def plot_linearmap(cdict):
161164
plot_linearmap(cdict)
162165

163166
#############################################################################
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.
167+
# In order to make a discontinuity at an anchor point, the third column is
168+
# different than the second. The matrix for each or "red", "green", "blue",
169+
# and optionally "alpha" is set up as::
170+
#
171+
# [...
172+
# [x[i] yleft[i] yright[i]],
173+
# [x[i+1] yleft[i+1] yright[i+1]]
174+
# ...]
175+
#
176+
# where the third column is the interpolation value
177+
# to the right of the anchor, and the second column the value to the left.
178+
# So, the linear interpolation between ``x[i]`` and
179+
# ``x[i+1]`` is from ``yright[i]`` to ``yleft[i+1] ``.
180+
#
181+
# In the example below there is a discontiuity in red at 0.5. The
182+
# interpolation between 0 and 0.5 goes from 0.3 to 1, and between 0.5 and 1
183+
# it goes from 0.9 to 1. Note that red[0, 1], and red[2, 2] are both
184+
# superfluous to the interpolation because red[0, 1] is the value to the
185+
# left of 0, and red[2, 2] is the value to the right of 1.0.
172186

173187
cdict['red'] = [[0.0, 0.0, 0.3],
174188
[0.5, 1.0, 0.9],

0 commit comments

Comments
 (0)