|
55 | 55 | print('viridis(np.linspace(0, 1, 15))', viridis(np.linspace(0, 1, 15)))
|
56 | 56 |
|
57 | 57 | ##############################################################################
|
58 |
| -# Creating a new ListedColormap |
59 |
| -# ============================= |
| 58 | +# Creating Listed colormaps |
| 59 | +# ========================= |
60 | 60 | #
|
61 | 61 | # This is essential the inverse operation of the above where we supply a
|
62 | 62 | # Nx4 numpy array with all values between 0 and 1,
|
@@ -123,15 +123,19 @@ def plot_examples(cms):
|
123 | 123 | plot_examples([viridis, newcmp])
|
124 | 124 |
|
125 | 125 | ##############################################################################
|
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. |
128 | 131 | #
|
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. |
132 | 137 | #
|
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]``: |
135 | 139 |
|
136 | 140 | cdict = {'red': [[0.0, 0.0, 0.0],
|
137 | 141 | [0.5, 1.0, 1.0],
|
@@ -161,14 +165,23 @@ def plot_linearmap(cdict):
|
161 | 165 | plot_linearmap(cdict)
|
162 | 166 |
|
163 | 167 | #############################################################################
|
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. |
172 | 185 |
|
173 | 186 | cdict['red'] = [[0.0, 0.0, 0.3],
|
174 | 187 | [0.5, 1.0, 0.9],
|
|
0 commit comments