8000 Merge pull request #14519 from timhoffm/colorbarbase-argcheck · matplotlib/matplotlib@3253ba1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3253ba1

Browse files
authored
Merge pull request #14519 from timhoffm/colorbarbase-argcheck
Check parameters of ColorbarBase
2 parents e86c9cd + 936905e commit 3253ba1

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

lib/matplotlib/colorbar.py

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -350,40 +350,78 @@ def get_clim(self):
350350

351351

352352
class ColorbarBase(_ColorbarMappableDummy):
353-
'''
353+
r"""
354354
Draw a colorbar in an existing axes.
355355
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.
360365
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
364368
under- and over-value colors, specify the *norm* as::
365369
366-
colors.Normalize(clip=False)
370+
norm=colors.Normalize(clip=False)
367371
368372
To show the colors versus index instead of on the 0-1 scale,
369373
use::
370374
371-
norm=colors.NoNorm.
375+
norm=colors.NoNorm()
372376
373377
Useful public methods are :meth:`set_label` and :meth:`add_lines`.
374378
375379
Attributes
376380
----------
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.
380383
lines : list
381-
A list of `LineCollection` if lines were drawn, otherwise
384+
A list of `.LineCollection` if lines were drawn, otherwise
382385
an empty list.
383-
384-
dividers : LineCollection
386+
dividers : `.LineCollect 10000 ion`
385387
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+
"""
387425
_slice_dict = {'neither': slice(0, None),
388426
'both': slice(1, -1),
389427
'min': slice(1, None),
@@ -408,7 +446,17 @@ def __init__(self, ax, cmap=None,
408446
extendrect=False,
409447
label='',
410448
):
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+
412460
self.ax = ax
413461
self._patch_ax()
414462
if cmap is None:

0 commit comments

Comments
 (0)
0