@@ -350,40 +350,78 @@ def get_clim(self):
350
350
351
351
352
352
class ColorbarBase (_ColorbarMappableDummy ):
353
- '''
353
+ r"""
354
354
Draw a colorbar in an existing axes.
355
355
356
- This is a base class for the :class:`Colorbar` class, which is the
357
- basis for the :func:`~matplotlib.pyplot.colorbar` function and the
358
- :meth:`~matplotlib.figure.Figure.colorbar` method, which are the
359
- usual ways of creating a colorbar.
356
+ There are only some rare cases in which you would work directly with a
357
+ `.ColorbarBase` as an end-user. Typically, colorbars are used
358
+ with `.ScalarMappable`\s such as an `.AxesImage` generated via
359
+ `~.axes.Axes.imshow`. For these cases you will use `.Colorbar` and
360
+ likely create it via `.pyplot.colorbar` or `.Figure.colorbar`.
361
+
362
+ The main application of using a `.ColorbarBase` explicitly is drawing
363
+ colorbars that are not associated with other elements in the figure, e.g.
364
+ when showing a colormap by itself.
360
365
361
- It is also useful by itself for showing a colormap. If the *cmap*
362
- kwarg is given but *boundaries* and *values* are left as None,
363
- then the colormap will be displayed on a 0-1 scale. To show the
366
+ If the *cmap* kwarg is given but *boundaries* and *values* are left as
367
+ None, then the colormap will be displayed on a 0-1 scale. To show the
364
368
under- and over-value colors, specify the *norm* as::
365
369
366
- colors.Normalize(clip=False)
370
+ norm= colors.Normalize(clip=False)
367
371
368
372
To show the colors versus index instead of on the 0-1 scale,
369
373
use::
370
374
371
- norm=colors.NoNorm.
375
+ norm=colors.NoNorm()
372
376
373
377
Useful public methods are :meth:`set_label` and :meth:`add_lines`.
374
378
375
379
Attributes
376
380
----------
377
- ax : Axes
378
- The `Axes` instance in which the colorbar is drawn.
379
-
381
+ ax : `~matplotlib.axes.Axes`
382
+ The `~.axes.Axes` instance in which the colorbar is drawn.
380
383
lines : list
381
- A list of `LineCollection` if lines were drawn, otherwise
384
+ A list of `. LineCollection` if lines were drawn, otherwise
382
385
an empty list.
383
-
384
- dividers : LineCollection
386
+ dividers : `.LineCollection`
385
387
A LineCollection if *drawedges* is ``True``, otherwise ``None``.
386
- '''
388
+
389
+ Parameters
390
+ ----------
391
+ ax : `~matplotlib.axes.Axes`
392
+ The `~.axes.Axes` instance in which the colorbar is drawn.
393
+ cmap : `~matplotlib.colors.Colormap` or None
394
+ The colormap to use. If *None*, use :rc:`image.cmap`.
395
+ norm : `~matplotlib.colors.Normalize`
396
+
397
+ alpha : float
398
+
399
+ values
400
+
401
+ boundaries
402
+
403
+ orientation : {'vertical', 'horizontal'}
404
+
405
+ ticklocation : {'auto', 'left', 'right', 'top', 'bottom'}
406
+
407
+ extend : {'neiter', 'both', 'min', 'max'}
408
+
409
+ spacing : {'uniform', 'proportional'}
410
+
411
+ ticks : `~matplotlib.ticker.Locator` or array-like of float
412
+
413
+ format : str or `~matplotlib.ticker.Formatter`
414
+
415
+ drawedges : bool
416
+
417
+ filled : bool
418
+
419
+ extendfrac
420
+
421
+ extendrec
422
+
423
+ label : str
424
+ """
387
425
_slice_dict = {'neither' : slice (0 , None ),
388
426
'both' : slice (1 , - 1 ),
389
427
'min' : slice (1 , None ),
@@ -408,7 +446,17 @@ def __init__(self, ax, cmap=None,
408
446
extendrect = False ,
409
447
label = '' ,
410
448
):
411
- #: The axes that this colorbar lives in.
449
+ cbook ._check_isinstance ([colors .Colormap , None ], cmap = cmap )
450
+ cbook ._check_in_list (
451
+ ['vertical' , 'horizontal' ], orientation = orientation )
452
+ cbook ._check_in_list (
453
+ ['auto' , 'left' , 'right' , 'top' , 'bottom' ],
454
+ ticklocation = ticklocation )
455
+ cbook ._check_in_list (
456
+ self ._slice_dict , extend = extend )
457
+ cbook ._check_in_list (
458
+ ['uniform' , 'proportional' ], spacing = spacing )
459
+
412
460
self .ax = ax
413
461
self ._patch_ax ()
414
462
if cmap is None :
0 commit comments