|
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 ListedColormaps |
| 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,14 @@ def plot_examples(cms):
|
123 | 123 | plot_examples([viridis, newcmp])
|
124 | 124 |
|
125 | 125 | ##############################################################################
|
126 |
| -# LinearSegmented colormaps |
127 |
| -# ========================= |
| 126 | +# Creating LinearSegmented colormaps |
| 127 | +# ================================== |
128 | 128 | #
|
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. |
132 | 131 | #
|
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: |
135 | 134 |
|
136 | 135 | cdict = {'red': [[0.0, 0.0, 0.0],
|
137 | 136 | [0.5, 1.0, 1.0],
|
@@ -161,14 +160,28 @@ def plot_linearmap(cdict):
|
161 | 160 | plot_linearmap(cdict)
|
162 | 161 |
|
163 | 162 | #############################################################################
|
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 | +# |
| 171 | +# .. math:: |
| 172 | +# |
| 173 | +# \begin{pmatrix} |
| 174 | +# \hdotsfor[]{3} |
| 175 | +# x_i & yleft_i & yright_i \\ |
| 176 | +# x_{i+1} & yleft_{i+1} & yright_{i+1} \\ |
| 177 | +# \hdotsfor[]{3} |
| 178 | +# \end{pmatrix} |
| 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