Colorbar toolkit with two classes and a function:
ColorbarBase
Colorbar
make_axes()
The colorbar()
method uses make_axes()
and Colorbar
; the colorbar()
function is a thin wrapper over colorbar()
.
class matplotlib.colorbar.Colorbar(ax, mappable, **kw)
[source]
Bases: matplotlib.colorbar.ColorbarBase
This class connects a ColorbarBase
to a ScalarMappable
such as a AxesImage
generated via imshow()
.
It is not intended to be instantiated directly; instead, use colorbar()
or colorbar()
to make your colorbar.
add_lines(self, CS, erase=True)
[source]
Add the lines from a non-filled ContourSet
to the colorbar.
Set erase to False if these lines should be added to any pre-existing lines.
on_mappable_changed(self, mappable)
[source]
Updates this colorbar to match the mappable's properties.
Typically this is automatically registered as an event handler by colorbar_factory()
and should not be called manually.
remove(self)
[source]
Remove this colorbar from the figure. If the colorbar was created with use_gridspec=True
then restore the gridspec to its previous value.
update_bruteforce(self, mappable)
[source]
Destroy and rebuild the colorbar. This is intended to become obsolete, and will probably be deprecated and then removed. It is not called when the pyplot.colorbar function or the Figure.colorbar method are used to create the colorbar.
update_normal(self, mappable)
[source]
Update solid patches, lines, etc.
Unlike update_bruteforce
, this does not clear the axes. This is meant to be called when the norm of the image or contour plot to which this colorbar belongs changes.
If the norm on the mappable is different than before, this resets the locator and formatter for the axis, so if these have been customized, they will need to be customized again. However, if the norm only changes values of vmin, vmax or cmap then the old formatter and locator will be preserved.
class matplotlib.colorbar.ColorbarBase(ax, cmap=None, norm=None, alpha=None, values=None, boundaries=None, orientation='vertical', ticklocation='auto', extend='neither', spacing='uniform', ticks=None, format=None, drawedges=False, filled=True, extendfrac=None, extendrect=False, label='')
[source]
Bases: matplotlib.colorbar._ColorbarMappableDummy
Draw a colorbar in an existing axes.
This is a base class for the Colorbar
class, which is the basis for the colorbar()
function and the colorbar()
method, which are the usual ways of creating a colorbar.
It is also useful by itself for showing a colormap. If the cmap kwarg is given but boundaries and values are left as None, then the colormap will be displayed on a 0-1 scale. To show the under- and over-value colors, specify the norm as:
colors.Normalize(clip=False)
To show the colors versus index instead of on the 0-1 scale, use:
norm=colors.NoNorm.
Useful public methods are set_label()
and add_lines()
.
Attributes: |
|
---|
add_lines(self, levels, colors, linewidths, erase=True)
[source]
Draw lines on the colorbar.
colors and linewidths must be scalars or sequences the same length as levels.
Set erase to False to add lines without first removing any previously added lines.
ax = None
The axes that this colorbar lives in.
config_axis(self)
[source]
draw_all(self)
[source]
Calculate any free parameters based on the current cmap and norm, and do all the drawing.
get_ticks(self, minor=False)
[source]
Return the x ticks as a list of locations.
minorticks_off(self)
[source]
Turns off the minor ticks on the colorbar.
minorticks_on(self)
[source]
Turns on the minor ticks on the colorbar without extruding into the "extend regions".
n_rasterize = 50
remove(self)
[source]
Remove this colorbar from the figure
set_alpha(self, alpha)
[source]
set_label(self, label, **kw)
[source]
Label the long axis of the colorbar.
set_ticklabels(self, ticklabels, update_ticks=True)
[source]
Set tick labels.
Tick labels are updated immediately unless update_ticks is False, in which case one should call update_ticks
explicitly.
set_ticks(self, ticks, update_ticks=True)
[source]
Set tick locations.
Parameters: |
|
---|
update_ticks(self)
[source]
Force the update of the ticks and ticklabels. This must be called whenever the tick locator and/or tick formatter changes.
class matplotlib.colorbar.ColorbarPatch(ax, mappable, **kw)
[source]
Bases: matplotlib.colorbar.Colorbar
A Colorbar which is created using Patch
rather than the default pcolor()
.
It uses a list of Patch instances instead of a PatchCollection
because the latter does not allow the hatch pattern to vary among the members of the collection.
matplotlib.colorbar.colorbar_factory(cax, mappable, **kwargs)
[source]
Creates a colorbar on the given axes for the given mappable.
Typically, for automatic colorbar placement given only a mappable use colorbar()
.
matplotlib.colorbar.make_axes(parents, location=None, orientation=None, fraction=0.15, shrink=1.0, aspect=20, **kw)
[source]
Resize and reposition parent axes, and return a child axes suitable for a colorbar.
Keyword arguments may include the following (with defaults):
location : [None|'left'|'right'|'top'|'bottom']
orientation
, else it will default to 'right'.orientation : [None|'vertical'|'horizontal']
location
keyword.Property | Description |
---|---|
orientation | vertical or horizontal |
fraction | 0.15; fraction of original axes to use for colorbar |
pad | 0.05 if vertical, 0.15 if horizontal; fraction of original axes between colorbar and new image axes |
shrink | 1.0; fraction by which to multiply the size of the colorbar |
aspect | 20; ratio of long to short dimensions |
anchor | (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal; the anchor point of the colorbar axes |
panchor | (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal; the anchor point of the colorbar parent axes. If False, the parent axes' anchor will be unchanged |
Returns (cax, kw), the child axes and the reduced kw dictionary to be passed when creating the colorbar instance.
matplotlib.colorbar.make_axes_gridspec(parent, *, fraction=0.15, shrink=1.0, aspect=20, **kw)
[source]
Resize and reposition a parent axes, and return a child axes suitable for a colorbar. This function is similar to make_axes. Prmary differences are
While this function is meant to be compatible with make_axes, there could be some minor differences.
Keyword arguments may include the following (with defaults):
Property | Description |
---|---|
orientation | vertical or horizontal |
fraction | 0.15; fraction of original axes to use for colorbar |
pad | 0.05 if vertical, 0.15 if horizontal; fraction of original axes between colorbar and new image axes |
shrink | 1.0; fraction by which to multiply the size of the colorbar |
aspect | 20; ratio of long to short dimensions |
anchor | (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal; the anchor point of the colorbar axes |
panchor | (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal; the anchor point of the colorbar parent axes. If False, the parent axes' anchor will be unchanged |
All but the first of these are stripped from the input kw set.
Returns (cax, kw), the child axes and the reduced kw dictionary to be passed when creating the colorbar instance.
© 2012–2018 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.1.1/api/colorbar_api.html