|
42 | 42 | ###############################################################################
|
43 | 43 | # Extended colorbar with continuous colorscale
|
44 | 44 | # --------------------------------------------
|
45 |
| - |
| 45 | +# |
46 | 46 | # The second example shows how to make a discrete colorbar based on a
|
47 |
| -# continuous cmap. With the "extend" kwarg the appropriate colors are chosen to |
48 |
| -# fill the colorspace, including the extensions: |
| 47 | +# continuous cmap. With the "extend" keyword argument the appropriate colors |
| 48 | +# are chosen to fill the colorspace, including the extensions: |
49 | 49 | fig, ax = plt.subplots(figsize=(6, 1))
|
50 | 50 | fig.subplots_adjust(bottom=0.5)
|
51 | 51 |
|
|
62 | 62 | # Discrete intervals colorbar
|
63 | 63 | # ---------------------------
|
64 | 64 | #
|
65 |
| -# The second example illustrates the use of a |
| 65 | +# The third example illustrates the use of a |
66 | 66 | # :class:`~matplotlib.colors.ListedColormap` which generates a colormap from a
|
67 | 67 | # set of listed colors, `.colors.BoundaryNorm` which generates a colormap
|
68 | 68 | # index based on discrete intervals and extended ends to show the "over" and
|
|
74 | 74 | # bounds array must be one greater than the length of the color list. The
|
75 | 75 | # bounds must be monotonically increasing.
|
76 | 76 | #
|
77 |
| -# This time we pass some more arguments in addition to previous arguments to |
78 |
| -# `~.Figure.colorbar`. For the out-of-range values to |
79 |
| -# display on the colorbar, we have to use the *extend* keyword argument. To use |
80 |
| -# *extend*, you must specify two extra boundaries. Finally spacing argument |
81 |
| -# ensures that intervals are shown on colorbar proportionally. |
| 77 | +# This time we pass additional arguments to |
| 78 | +# `~.Figure.colorbar`. For the out-of-range values to display on the colorbar |
| 79 | +# without using the *extend* keyword with |
| 80 | +# `.colors.BoundaryNorm`, we have to use the *extend* keyword argument directly |
| 81 | +# in the colorbar call, and supply an additional boundary on each end of the |
| 82 | +# range. Here we also |
| 83 | +# use the spacing argument to make |
| 84 | +# the length of each colorbar segment proportional to its corresponding |
| 85 | +# interval. |
82 | 86 |
|
83 | 87 | fig, ax = plt.subplots(figsize=(6, 1))
|
84 | 88 | fig.subplots_adjust(bottom=0.5)
|
|
92 | 96 | fig.colorbar(
|
93 | 97 | mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
|
94 | 98 | cax=ax,
|
95 |
| - boundaries=[0] + bounds + [13], |
| 99 | + boundaries=[0] + bounds + [13], # Adding values for extensions. |
96 | 100 | extend='both',
|
97 | 101 | ticks=bounds,
|
98 | 102 | spacing='proportional',
|
|
104 | 108 | # Colorbar with custom extension lengths
|
105 | 109 | # --------------------------------------
|
106 | 110 | #
|
107 |
| -# Here we illustrate the use of custom length colorbar extensions, used on a |
| 111 | +# Here we illustrate the use of custom length colorbar extensions, on a |
108 | 112 | # colorbar with discrete intervals. To make the length of each extension the
|
109 | 113 | # same as the length of the interior colors, use ``extendfrac='auto'``.
|
110 | 114 |
|
|
0 commit comments