@@ -170,24 +170,32 @@ def colorbar(
170
170
>>> import mplotutils as mpu
171
171
>>> import cartopy.crs as ccrs
172
172
173
+ >>> # example data
174
+ >>> da = mpu.sample_dataarray(36, 18)
175
+ >>> # plotting options
176
+ >>> opt = {"add_colorbar": False, "transform": ccrs.PlateCarree()}
177
+
173
178
>>> # =========================
174
179
>>> # example with 1 axes
175
180
176
181
>>> f, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()})
177
- >>> h = ax.pcolormesh([[0, 1]])
178
- >>> ax.coastlines()
179
- >>> mpu.colorbar(h, ax)
182
+ >>> ax.coastlines() # doctest: +SKIP
180
183
>>> ax.set_global()
184
+ >>> h = da.plot(ax=ax, **opt)
185
+
186
+ >>> cbar = mpu.colorbar(h, ax)
181
187
182
188
>>> # =========================
183
189
>>> # example with 2 axes
184
190
185
191
>>> f, axs = plt.subplots(2, 1, subplot_kw={"projection": ccrs.PlateCarree()})
186
192
187
193
>>> for ax in axs:
188
- >>> ax.coastlines()
189
- >>> ax.set_global()
190
- >>> h = ax.pcolormesh([[0, 1]])
194
+ ... ax.coastlines() # doctest: +SKIP
195
+ ... ax.set_global()
196
+
197
+ >>> h = da.plot(ax=axs[0], **opt)
198
+ >>> h = da.plot(ax=axs[1], **opt)
191
199
192
200
>>> cbar = mpu.colorbar(h, axs)
193
201
@@ -197,15 +205,15 @@ def colorbar(
197
205
>>> f, axs = plt.subplots(3, 1, subplot_kw={"projection": ccrs.PlateCarree()})
198
206
199
207
>>> for ax in axs:
200
- >>> ax.coastlines()
201
- >>> ax.set_global()
208
+ ... ax.coastlines() # doctest: +SKIP
209
+ ... ax.set_global()
202
210
203
- >>> h0 = ax.pcolormesh([[0, 1]] )
204
- >>> h1 = ax.pcolormesh([[0, 1]] )
205
- >>> h2 = ax.pcolormesh([[0, 1]] , cmap='Blues')
211
+ >>> h0 = da.plot(ax=axs[0], **opt )
212
+ >>> h1 = da.plot(ax=axs[1], **opt )
213
+ >>> h2 = da.plot(ax=axs[2] , cmap='Blues', **opt )
206
214
207
- >>> cbar = mpu.colorbar(h , [axs[0], axs[1]], size=0.05)
208
- >>> cbar = mpu.colorbar(h , axs[2], size=0.05)
215
+ >>> cbar = mpu.colorbar(h0 , [axs[0], axs[1]], size=0.05)
216
+ >>> cbar = mpu.colorbar(h2 , axs[2], size=0.05)
209
217
210
218
Notes
211
219
-----
@@ -244,7 +252,7 @@ def colorbar(
244
252
# ensure mpu.colorbar does not change the current axes
245
253
plt .sca (gca )
246
254
247
- cbar = plt .colorbar (mappable , orientation = orientation , cax = cbax , ** kwargs )
255
+ cbar = f .colorbar (mappable , orientation = orientation , cax = cbax , ** kwargs )
248
256
249
257
if orientation == "vertical" :
250
258
func = _resize_colorbar_vert (
@@ -298,37 +306,6 @@ def _resize_colorbar_vert(
298
306
shift = "symmetric" ,
299
307
shrink = None ,
300
308
):
301
- """
302
- automatically resize colorbars on draw
303
-
304
- see 'colorbar'
305
-
306
- Examples
307
- --------
308
- >>> import matplotlib.pyplot as plt
309
- >>> import mplotutils as mpu
310
- >>> import cartopy.crs as ccrs
311
-
312
- >>> f = plt.figure()
313
- >>> ax = plt.axes(projection=ccrs.PlateCarree())
314
- >>> h = ax.pcolormesh([[0, 1]])
315
-
316
- >>> ax.coastlines()
317
-
318
- >>> cbax = f.add_axes([0, 0, 0.1, 0.1])
319
- >>> cbar = plt.colorbar(h, orientation='vertical', cax=cbax)
320
-
321
- >>> func = mpu._resize_colorbar_vert(cbax, ax)
322
- >>> f.canvas.mpl_connect('draw_event', func)
323
-
324
- >>> ax.set_global()
325
-
326
- >>> plt.draw()
327
-
328
- See Also
329
- --------
330
- _resize_colorbar_horz
331
- """
332
309
333
310
shift , shrink = _parse_shift_shrink (shift , shrink )
334
311
@@ -384,36 +361,6 @@ def _resize_colorbar_horz(
384
361
shift = "symmetric" ,
385
362
shrink = None ,
386
363
):
387
- """
388
- automatically resize colorbars on draw
389
-
390
- see 'colorbar'
391
-
392
- Examples
393
- --------
394
- >>> import matplotlib.pyplot as plt
395
- >>> import mplotutils as mpu
396
- >>> import cartopy.crs as ccrs
397
-
398
- >>> f = plt.figure()
399
- >>> ax = plt.axes(projection=ccrs.PlateCarree())
400
-
401
- >>> ax.coastlines()
402
-
403
- >>> cbax = f.add_axes([0, 0, 0.1, 0.1])
404
- >>> cbar = plt.colorbar(h, orientation='horizontal', cax=cbax)
405
-
406
- >>> func = mpu._resize_colorbar_horz(cbax, ax)
407
- >>> f.canvas.mpl_connect('draw_event', func)
408
-
409
- >>> ax.set_global()
410
-
411
- >>> plt.draw()
412
-
413
- See Also
414
- --------
415
- _resize_colorbar_vert
416
- """
417
364
418
365
shift , shrink = _parse_shift_shrink (shift , shrink )
419
366
0 commit comments