Add a colorbar to a plot.
The matplotlib.cm.ScalarMappable
(i.e., AxesImage
, ContourSet
, etc.) described by this colorbar. This argument is mandatory for the Figure.colorbar
method but optional for the pyplot.colorbar
function, which sets the default to the current image.
Note that one can create a ScalarMappable
"on-the-fly" to generate colorbars not attached to a previously drawn artist, e.g.
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax)
Axes
, optional
Axes into which the colorbar will be drawn. If None
, then a new Axes is created and the space for it will be stolen from the Axes(s) specified in ax.
Axes
or iterable or numpy.ndarray
of Axes, optional
The one or more parent Axes from which space for a new colorbar Axes will be stolen. This parameter is only used if cax is not set.
Defaults to the Axes that contains the mappable used to create the colorbar.
If cax is None
, a new cax is created as an instance of Axes. If ax is positioned with a subplotspec and use_gridspec is True
, then cax is also positioned with a subplotspec.
Colorbar
The location, relative to the parent Axes, where the colorbar Axes is created. It also determines the orientation of the colorbar (colorbars on the left and right are vertical, colorbars at the top and bottom are horizontal). If None, the location will come from the orientation if it is set (vertical colorbars on the right, horizontal ones at the bottom), or default to 'right' if orientation is unset.
The orientation of the colorbar. It is preferable to set the location of the colorbar, as that also determines the orientation; passing incompatible values for location and orientation raises an exception.
Fraction of original Axes to use for colorbar.
Fraction by which to multiply the size of the colorbar.
Ratio of long to short dimensions.
Fraction of original Axes between colorbar and new image Axes.
The anchor point of the colorbar Axes. Defaults to (0.0, 0.5) if vertical; (0.5, 1.0) if horizontal.
The anchor point of the colorbar parent Axes. If False, the parent axes' anchor will be unchanged. Defaults to (1.0, 0.5) if vertical; (0.5, 0.0) if horizontal.
Make pointed end(s) for out-of-range values (unless 'neither'). These are set for a given colormap using the colormap set_under and set_over methods.
If set to None, both the minimum and maximum triangular colorbar extensions will have a length of 5% of the interior colorbar length (this is the default setting).
If set to 'auto', makes the triangular colorbar extensions the same lengths as the interior boxes (when spacing is set to 'uniform') or the same lengths as the respective adjacent interior boxes (when spacing is set to 'proportional').
If a scalar, indicates the length of both the minimum and maximum triangular colorbar extensions as a fraction of the interior colorbar length. A two-element sequence of fractions may also be given, indicating the lengths of the minimum and maximum colorbar extensions respectively as a fraction of the interior colorbar length.
If False the minimum and maximum colorbar extensions will be triangular (the default). If True the extensions will be rectangular.
If None, ticks are determined automatically from the input.
If None, ScalarFormatter
is used. Format strings, e.g., "%4.2e"
or "{x:.2e}"
, are supported. An alternative Formatter
may be given instead.
Whether to draw lines at color boundaries.
The label on the colorbar's long axis.
If unset, the colormap will be displayed on a 0-1 scale. If sequences, values must have a length 1 less than boundaries. For each region delimited by adjacent entries in boundaries, the color mapped to the corresponding value in values will be used. The size of each region is determined by the spacing parameter. Normally only useful for indexed colors (i.e. norm=NoNorm()
) or other unusual circumstances.
For discrete colorbars (BoundaryNorm
or contours), 'uniform' gives each color the same space; 'proportional' makes the space proportional to the data interval.
Notes
If mappable is a ContourSet
, its extend kwarg is included automatically.
The shrink kwarg provides a simple way to scale the colorbar with respect to the Axes. Note that if cax is specified, it determines the size of the colorbar, and shrink and aspect are ignored.
For more precise control, you can manually specify the positions of the axes objects in which the mappable and the colorbar are drawn. In this case, do not use any of the Axes properties kwargs.
It is known that some vector graphics viewers (svg and pdf) render white gaps between segments of the colorbar. This is due to bugs in the viewers, not Matplotlib. As a workaround, the colorbar can be rendered with overlapping segments:
cbar = colorbar() cbar.solids.set_edgecolor("face") draw()
However, this has negative consequences in other circumstances, e.g. with semi-transparent images (alpha < 1) and colorbar extensions; therefore, this workaround is not used by default (see issue #1188).
matplotlib.figure.Figure.colorbar
#
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4