|
20 | 20 | Artists that map data to color pass the arguments *vmin* and *vmax* to |
21 | 21 | construct a :func:`matplotlib.colors.Normalize` instance, then call it: |
22 | 22 |
|
23 | | -.. ipython:: |
| 23 | +.. code-block:: pycon |
24 | 24 |
|
25 | | - In [1]: import matplotlib as mpl |
26 | | -
|
27 | | - In [2]: norm = mpl.colors.Normalize(vmin=-1, vmax=1) |
28 | | -
|
29 | | - In [3]: norm(0) |
30 | | - Out[3]: 0.5 |
| 25 | + >>> import matplotlib as mpl |
| 26 | + >>> norm = mpl.colors.Normalize(vmin=-1, vmax=1) |
| 27 | + >>> norm(0) |
| 28 | + 0.5 |
31 | 29 |
|
32 | 30 | However, there are sometimes cases where it is useful to map data to |
33 | 31 | colormaps in a non-linear fashion. |
|
192 | 190 | # lower out-of-bounds values to the range over which the colors are |
193 | 191 | # distributed. For instance: |
194 | 192 | # |
195 | | -# .. ipython:: |
196 | | -# |
197 | | -# In [2]: import matplotlib.colors as colors |
198 | | -# |
199 | | -# In [3]: bounds = np.array([-0.25, -0.125, 0, 0.5, 1]) |
200 | | -# |
201 | | -# In [4]: norm = colors.BoundaryNorm(boundaries=bounds, ncolors=4) |
| 193 | +# .. code-block:: pycon |
202 | 194 | # |
203 | | -# In [5]: print(norm([-0.2, -0.15, -0.02, 0.3, 0.8, 0.99])) |
| 195 | +# >>> import matplotlib.colors as colors |
| 196 | +# >>> bounds = np.array([-0.25, -0.125, 0, 0.5, 1]) |
| 197 | +# >>> norm = colors.BoundaryNorm(boundaries=bounds, ncolors=4) |
| 198 | +# >>> print(norm([-0.2, -0.15, -0.02, 0.3, 0.8, 0.99])) |
204 | 199 | # [0 0 1 2 3 3] |
205 | 200 | # |
206 | 201 | # Note: Unlike the other norms, this norm returns values from 0 to *ncolors*-1. |
|
0 commit comments