@@ -90,102 +90,130 @@ def colorbar(
90
90
shrink : None or float in 0..1, default: None.
91
91
Fraction of the total height that the colorbar is shrunk. See Note.
92
92
**kwargs : keyword arguments
93
- colorbar properties
94
- ============ ====================================================
95
- Property Description
96
- ============ ====================================================
97
- *extend* [ 'neither' | 'both' | 'min' | 'max' ]
98
- If not 'neither', make pointed end(s) for out-of-
99
- range values. These are set for a given colormap
100
- using the colormap set_under and set_over methods.
101
- *extendfrac* [ *None* | 'auto' | length | lengths ]
102
- If set to *None*, both the minimum and maximum
103
- triangular colorbar extensions with have a length of
104
- 5% of the interior colorbar length (this is the
105
- default setting). If set to 'auto', makes the
106
- triangular colorbar extensions the same lengths as
107
- the interior boxes (when *spacing* is set to
108
- 'uniform') or the same lengths as the respective
109
- adjacent interior boxes (when *spacing* is set to
110
- 'proportional'). If a scalar, indicates the length
111
- of both the minimum and maximum triangular colorbar
112
- extensions as a fraction of the interior colorbar
113
- length. A two-element sequence of fractions may also
114
- be given, indicating the lengths of the minimum and
115
- maximum colorbar extensions respectively as a
116
- fraction of the interior colorbar length.
117
- *extendrect* [ *False* | *True* ]
118
- If *False* the minimum and maximum colorbar extensions
119
- will be triangular (the default). If *True* the
120
- extensions will be rectangular.
121
- *spacing* [ 'uniform' | 'proportional' ]
122
- Uniform spacing gives each discrete color the same
123
- space; proportional makes the space proportional to
124
- the data interval.
125
- *ticks* [ None | list of ticks | Locator object ]
126
- If None, ticks are determined automatically from the
127
- input.
128
- *format* [ None | format string | Formatter object ]
129
- If None, the
130
- :class:`~matplotlib.ticker.ScalarFormatter` is used.
131
- If a format string is given, e.g., '%.3f', that is
132
- used. An alternative
133
- :class:`~matplotlib.ticker.Formatter` object may be
134
- given instead.
135
- *drawedges* [ False | True ] If true, draw lines at color
136
- boundaries.
137
- ============ ====================================================
93
+ See Other Parameters.
94
+
95
+ Other Parameters
96
+ ----------------
97
+ location : None or {'left', 'right', 'top', 'bottom'}
98
+ The location, relative to the parent Axes, where the colorbar Axes
99
+ is created. It also determines the *orientation* of the colorbar
100
+ (colorbars on the left and right are vertical, colorbars at the top
101
+ and bottom are horizontal). If None, the location will come from the
102
+ *orientation* if it is set (vertical colorbars on the right, horizontal
103
+ ones at the bottom), or default to 'right' if *orientation* is unset.
104
+
105
+ orientation : None or {'vertical', 'horizontal'}
106
+ The orientation of the colorbar. It is preferable to set the *location*
107
+ of the colorbar, as that also determines the *orientation*; passing
108
+ incompatible values for *location* and *orientation* raises an exception.
109
+
110
+ fraction : float, default: 0.15
111
+ Fraction of original Axes to use for colorbar.
112
+
113
+ shrink : float, default: 1.0
114
+ Fraction by which to multiply the size of the colorbar.
115
+
116
+ extend : {'neither', 'both', 'min', 'max'}
117
+ Make pointed end(s) for out-of-range values (unless 'neither'). These are
118
+ set for a given colormap using the colormap set_under and set_over methods.
119
+
120
+ extendfrac : {*None*, 'auto', length, lengths}
121
+ If set to *None*, both the minimum and maximum triangular colorbar
122
+ extensions will have a length of 5% of the interior colorbar length (this
123
+ is the default setting).
124
+
125
+ If set to 'auto', makes the triangular colorbar extensions the same lengths
126
+ as the interior boxes (when *spacing* is set to 'uniform') or the same
127
+ lengths as the respective adjacent interior boxes (when *spacing* is set to
128
+ 'proportional').
129
+
130
+ If a scalar, indicates the length of both the minimum and maximum
131
+ triangular colorbar extensions as a fraction of the interior colorbar
132
+ length. A two-element sequence of fractions may also be given, indicating
133
+ the lengths of the minimum and maximum colorbar extensions respectively as
134
+ a fraction of the interior colorbar length.
135
+
136
+ extendrect : bool, default: False
137
+ If *False* the minimum and maximum colorbar extensions will be triangular
138
+ (the default). If *True* the extensions will be rectangular.
139
+
140
+ spacing : {'uniform', 'proportional'}
141
+ For discrete colorbars (`.BoundaryNorm` or contours), 'uniform' gives each
142
+ color the same space; 'proportional' makes the space proportional to the
143
+ data interval.
144
+
145
+ ticks : None or list of ticks or Locator
146
+ If None, ticks are determined automatically from the input.
147
+
148
+ format : None or str or Formatter
149
+ If None, `~.ticker.ScalarFormatter` is used.
150
+ Format strings, e.g., ``"%4.2e"`` or ``"{x:.2e}"``, are supported.
151
+ An alternative `~.ticker.Formatter` may be given instead.
152
+
153
+ drawedges : bool
154
+ Whether to draw lines at color boundaries.
155
+
156
+ label : str
157
+ The label on the colorbar's long axis.
158
+
159
+ boundaries, values : None or a sequence
160
+ If unset, the colormap will be displayed on a 0-1 scale.
161
+ If sequences, *values* must have a length 1 less than *boundaries*. For
162
+ each region delimited by adjacent entries in *boundaries*, the color mapped
163
+ to the corresponding value in values will be used.
164
+ Normally only useful for indexed colors (i.e. ``norm=NoNorm()``) or other
165
+ unusual circumstances.
138
166
139
167
Examples
140
168
--------
141
- import matplotlib.pyplot as plt
142
- import mplotutils as mpu
143
- import cartopy.crs as ccrs
169
+ >>> import matplotlib.pyplot as plt
170
+ >>> import mplotutils as mpu
171
+ >>> import cartopy.crs as ccrs
144
172
145
- # example with 1 axes
173
+ >>> # =========================
174
+ >>> # example with 1 axes
146
175
147
- f, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()})
148
- h = ax.pcolormesh([[0, 1]])
149
- ax.coastlines()
150
- mpu.colorbar(h, ax)
151
- ax.set_global()
176
+ >>> f, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()})
177
+ >>> h = ax.pcolormesh([[0, 1]])
178
+ >>> ax.coastlines()
179
+ >>> mpu.colorbar(h, ax)
180
+ >>> ax.set_global()
152
181
153
- # =========================
154
- # example with 2 axes
182
+ >>> # =========================
183
+ >>> # example with 2 axes
155
184
156
- f, axs = plt.subplots(2, 1, subplot_kw={"projection": ccrs.PlateCarree()})
185
+ >>> f, axs = plt.subplots(2, 1, subplot_kw={"projection": ccrs.PlateCarree()})
157
186
158
- for ax in axs:
159
- ax.coastlines()
160
- ax.set_global()
161
- h = ax.pcolormesh([[0, 1]])
187
+ >>> for ax in axs:
188
+ >>> ax.coastlines()
189
+ >>> ax.set_global()
190
+ >>> h = ax.pcolormesh([[0, 1]])
162
191
163
- cbar = mpu.colorbar(h, axs)
192
+ >>> cbar = mpu.colorbar(h, axs)
164
193
165
- # =========================
166
- # example with 3 axes & 2 colorbars
194
+ >>> # =========================
195
+ >>> # example with 3 axes & 2 colorbars
167
196
168
- f, axs = plt.subplots(3, 1, subplot_kw={"projection": ccrs.PlateCarree()})
197
+ >>> f, axs = plt.subplots(3, 1, subplot_kw={"projection": ccrs.PlateCarree()})
169
198
170
- for ax in axs:
171
- ax.coastlines()
172
- ax.set_global()
199
+ >>> for ax in axs:
200
+ >>> ax.coastlines()
201
+ >>> ax.set_global()
173
202
174
- h0 = ax.pcolormesh([[0, 1]])
175
- h1 = ax.pcolormesh([[0, 1]])
176
- h2 = ax.pcolormesh([[0, 1]], cmap='Blues')
203
+ >>> h0 = ax.pcolormesh([[0, 1]])
204
+ >>> h1 = ax.pcolormesh([[0, 1]])
205
+ >>> h2 = ax.pcolormesh([[0, 1]], cmap='Blues')
177
206
178
- cbar = mpu.colorbar(h, [axs[0], axs[1]], size=0.05)
179
- cbar = mpu.colorbar(h, axs[2], size=0.05)
180
-
181
- plt.draw()
207
+ >>> cbar = mpu.colorbar(h, [axs[0], axs[1]], size=0.05)
208
+ >>> cbar = mpu.colorbar(h, axs[2], size=0.05)
182
209
183
210
Notes
184
211
-----
185
212
- ``shift='symmetric', shrink=None`` -> colorbar extends over the whole height
186
213
- ``shift='symmetric', shrink=0.1`` -> colorbar is 10 % smaller, and centered
187
214
- ``shift=0., shrink=0.1`` -> colorbar is 10 % smaller, and aligned with the bottom
188
215
- ``shift=0.1, shrink=None`` -> colorbar is 10 % smaller, and aligned with the top
216
+ - the ``anchor`` and ``panchor`` keywords are not supported
189
217
190
218
See Also
191
219
--------
@@ -277,25 +305,25 @@ def _resize_colorbar_vert(
277
305
278
306
Examples
279
307
--------
280
- import matplotlib.pyplot as plt
281
- import mplotutils as mpu
282
- import cartopy.crs as ccrs
308
+ >>> import matplotlib.pyplot as plt
309
+ >>> import mplotutils as mpu
310
+ >>> import cartopy.crs as ccrs
283
311
284
- f = plt.figure()
285
- ax = plt.axes(projection=ccrs.PlateCarree())
286
- h = ax.pcolormesh([[0, 1]])
312
+ >>> f = plt.figure()
313
+ >>> ax = plt.axes(projection=ccrs.PlateCarree())
314
+ >>> h = ax.pcolormesh([[0, 1]])
287
315
288
- ax.coastlines()
316
+ >>> ax.coastlines()
289
317
290
- cbax = f.add_axes([0, 0, 0.1, 0.1])
291
- cbar = plt.colorbar(h, orientation='vertical', cax=cbax)
318
+ >>> cbax = f.add_axes([0, 0, 0.1, 0.1])
319
+ >>> cbar = plt.colorbar(h, orientation='vertical', cax=cbax)
292
320
293
- func = mpu._resize_colorbar_vert(cbax, ax)
294
- f.canvas.mpl_connect('draw_event', func)
321
+ >>> func = mpu._resize_colorbar_vert(cbax, ax)
322
+ >>> f.canvas.mpl_connect('draw_event', func)
295
323
296
- ax.set_global()
324
+ >>> ax.set_global()
297
325
298
- plt.draw()
326
+ >>> plt.draw()
299
327
300
328
See Also
301
329
--------
@@ -363,24 +391,24 @@ def _resize_colorbar_horz(
363
391
364
392
Examples
365
393
--------
366
- import matplotlib.pyplot as plt
367
- import mplotutils as mpu
368
- import cartopy.crs as ccrs
394
+ >>> import matplotlib.pyplot as plt
395
+ >>> import mplotutils as mpu
396
+ >>> import cartopy.crs as ccrs
369
397
370
- f = plt.figure()
371
- ax = plt.axes(projection=ccrs.PlateCarree())
398
+ >>> f = plt.figure()
399
+ >>> ax = plt.axes(projection=ccrs.PlateCarree())
372
400
373
- ax.coastlines()
401
+ >>> ax.coastlines()
374
402
375
- cbax = f.add_axes([0, 0, 0.1, 0.1])
376
- cbar = plt.colorbar(h, orientation='horizontal', cax=cbax)
403
+ >>> cbax = f.add_axes([0, 0, 0.1, 0.1])
404
+ >>> cbar = plt.colorbar(h, orientation='horizontal', cax=cbax)
377
405
378
- func = mpu._resize_colorbar_horz(cbax, ax)
379
- f.canvas.mpl_connect('draw_event', func)
406
+ >>> func = mpu._resize_colorbar_horz(cbax, ax)
407
+ >>> f.canvas.mpl_connect('draw_event', func)
380
408
381
- ax.set_global()
409
+ >>> ax.set_global()
382
410
383
- plt.draw()
411
+ >>> plt.draw()
384
412
385
413
See Also
386
414
--------
0 commit comments