Axes.colorbar¶
- Axes.colorbar(**kwargs)[source]¶
Add an inset colorbar or an outer colorbar along the edge of the axes.
- Parameters
mappable (
mappable,colormap-spec, sequence ofcolor-spec, or sequence ofArtist) – There are four options here:A
ScalarMappable(e.g., an object returned bycontourforpcolormesh).A
Colormapor registered colormap name used to build aScalarMappableon-the-fly. The colorbar range and ticks depend on the argumentsvalues,vmin,vmax, andnorm. The default for aContinuousColormapisvmin=0andvmax=1(note that passingvalueswill “discretize” the colormap). The default for aDiscreteColormapisvalues=np.arange(0, cmap.N).A sequence of hex strings, color names, or RGB[A] tuples. A
DiscreteColormapwill be generated from these colors and used to build aScalarMappableon-the-fly. The colorbar range and ticks depend on the argumentsvalues,norm, andnorm_kw. The default isvalues=np.arange(0, len(mappable)).A sequence of
matplotlib.artist.Artistinstances (e.g., a list ofLine2Dinstances returned byplot). A colormap will be generated from the colors of these objects (where the color is determined byget_color, if available, orget_facecolor). The colorbar range and ticks depend on the argumentsvalues,norm, andnorm_kw. The default is to infer colorbar ticks and tick labels by callingget_labelon each artist.
values (sequence of
floatorstr, optional) – Ignored ifmappableis aScalarMappable. This maps the colormap colors to numeric values usingDiscreteNorm. If the colormap is aContinuousColormapthen its colors will be “discretized”. These These can also be strings, in which case the list indices are used for tick locations and the strings are applied as tick labels.loc, location (
intorstr, default:rc['colorbar.loc']='right') – The colorbar location. Valid location keys are shown in the below table.Location
Valid keys
outer left
'left','l'outer right
'right','r'outer bottom
'bottom','b'outer top
'top','t'default inset
'best','inset','i',0upper right inset
'upper right','ur',1upper left inset
'upper left','ul',2lower left inset
'lower left','ll',3lower right inset
'lower right','lr',4“filled”
'fill'shrink – Alias for
length. This is included for consistency withmatplotlib.figure.Figure.colorbar.length (
floatorunit-spec, default:rc['colorbar.length']=1.0orrc['colorbar.insetlength']=8.0) – The colorbar length. For outer colorbars, units are relative to the axes width or height (default isrc['colorbar.length']). For inset colorbars, floats interpreted as em-widths and strings interpreted byunits(default isrc['colorbar.insetlength']).width (
unit-spec, default:rc['colorbar.width']=0.2or:rc:`colorbar.insetwidth) – The colorbar width. For outer colorbars, floats are interpreted as inches (default isrc['colorbar.width']). For inset colorbars, floats are interpreted as em-widths (default isrc['colorbar.insetwidth']). Strings are interpreted byunits.queue (
bool, optional) – IfTrueandlocis the same as an existing colorbar, the input arguments are added to a queue and this function returnsNone. This is used to “update” the same colorbar with successiveax.colorbar(...)calls. IfFalse(the default) andlocis the same as an existing inset colorbar, the old colorbar is removed. IfFalseandlocis an outer colorbar, the colorbars are “stacked”.space (
unit-spec, default:None) – For outer colorbars only. The fixed space between the colorbar and the subplot edge. If float, units are em-widths. If string, interpreted byunits. When the tight layout algorithm is active for the figure,spaceis computed automatically (seepad). Otherwise,spaceis set to a suitable default.pad (
unit-spec, default:rc['subplots.panelpad']=0.5orrc['colorbar.insetpad']=0.7) – For outer colorbars, this is the tight layout padding between the colorbar and the subplot (default isrc['subplots.panelpad']). For inset colorbars, this is the fixed space between the axes edge and the colorbar (default isrc['colorbar.insetpad']). If float, units are em-widths. If string, interpreted byunits.align (
{'center', 'top', 'bottom', 'left', 'right', 't', 'b', 'l', 'r'}, optional) – For outer colorbars only. How to align the colorbar against the subplot edge. The values'top'and'bottom'are valid for left and right colorbars and'left'and'right'are valid for top and bottom colorbars. The default is always'center'. Has no visible effect iflengthis1.
- Other Parameters
orientation (
{None, 'horizontal', 'vertical'}, optional) – The colorbar orientation. By default this depends on the “side” of the subplot or figure where the colorbar is drawn. Inset colorbars are always horizontal.norm (
norm-spec, optional) – Ignored ifmappableis aScalarMappable. This is the continuous normalizer used to scale theContinuousColormap(or passed toDiscreteNormifvalueswas passed). Passed to theNormconstructor function.norm_kw (dict-like, optional) – Ignored if
mappableis aScalarMappable. These are the normalizer keyword arguments. Passed toNorm.vmin, vmax (
float, optional) – Ignored ifmappableis aScalarMappable. These are the minimum and maximum colorbar values. Passed toNorm.label, title (
str, optional) – The colorbar label. Thetitlekeyword is also accepted for consistency withlegend.reverse (
bool, optional) – Whether to reverse the direction of the colorbar. This is done automatically when descending levels are used withDiscreteNorm.rotation (
float, default:0) – The tick label rotation.grid, edges, drawedges (
bool, default:rc['colorbar.grid']=False) – Whether to draw “grid” dividers between each distinct color.extend (
{'neither', 'both', 'min', 'max'}, optional) – Direction for drawing colorbar “extensions” (i.e. color keys for out-of-bounds data on the end of the colorbar). Default behavior is to use the value ofextendpassed to the plotting command or use'neither'if the value is unknown.extendfrac (
float, optional) – The length of the colorbar “extensions” relative to the length of the colorbar. This is a native matplotlibcolorbarkeyword.extendsize (
unit-spec, default:rc['colorbar.extend']=1.3orrc['colorbar.insetextend']=0.9) – The length of the colorbar “extensions” in physical units. Default isrc['colorbar.extend']for outer colorbars andrc['colorbar.insetextend']for inset colorbars. If float, units are em-widths. If string, interpreted byunits.extendrect (
bool, default:False) – Whether to draw colorbar “extensions” as rectangles. IfFalsethen the extensions are drawn as triangles.locator, ticks (
locator-spec, optional) – Used to determine the colorbar tick positions. Passed to theLocatorconstructor function. By defaultAutoLocatoris used for continuous color levels andDiscreteLocatoris used for discrete color levels.locator_kw (dict-like, optional) – Keyword arguments passed to
matplotlib.ticker.Locatorclass.minorlocator, minorticks – As with
locator,ticksbut for the minor ticks. By defaultAutoMinorLocatoris used for continuous color levels andDiscreteLocatoris used for discrete color levels.minorlocator_kw – As with
locator_kw, but for the minor ticks.format, formatter, ticklabels (
formatter-spec, optional) – The tick label format. Passed to theFormatterconstructor function.formatter_kw (dict-like, optional) – Keyword arguments passed to
matplotlib.ticker.Formatterclass.frame, frameon (
bool, default:rc['colorbar.frameon']=True) – For inset colorbars only. Indicates whether to draw a “frame”, just likelegend.tickminor (
bool, optional) – Whether to add minor ticks usingminorticks_on.tickloc, ticklocation (
{'bottom', 'top', 'left', 'right'}, optional) – Where to draw tick marks on the colorbar. Default is toward the outside of the subplot for outer colorbars and'bottom'for inset colorbars.tickdir, tickdirection (
{'out', 'in', 'inout'}, default:rc['tick.dir']='out') – Direction of major and minor colorbar ticks.ticklen (
unit-spec, default:rc['tick.len']=4.0) – Major tick lengths for the colorbar ticks.ticklenratio (
float, default:rc['tick.lenratio']=0.5) – Relative scaling ofticklenused to determine minor tick lengths.tickwidth (
unit-spec, default:linewidth) – Major tick widths for the colorbar ticks. orrc['tick.width']=0.6iflinewidthwas not passed.tickwidthratio (
float, default:rc['tick.widthratio']=0.8) – Relative scaling oftickwidthused to determine minor tick widths.ticklabelcolor, ticklabelsize, ticklabelweight (default:
rc['tick.labelcolor']='black',rc['tick.labelsize']='medium',rc['tick.labelweight']='normal'.) – The font color, size, and weight for colorbar tick labelslabelloc, labellocation (
{'bottom', 'top', 'left', 'right'}) – The colorbar label location. Inherits fromticklocby default. Default is toward the outside of the subplot for outer colorbars and'bottom'for inset colorbars.labelcolor, labelsize, labelweight (default:
rc['label.color']='black',rc['label.size']='medium', andrc['label.weight']='normal'.) – The font color, size, and weight for the colorbar label.a, alpha, framealpha, fc, facecolor, framecolor, ec, edgecolor, ew, edgewidth (default:
rc['colorbar.framealpha']=0.8,rc['colorbar.framecolor']) – For inset colorbars only. Controls the transparency and color of the background frame.lw, linewidth, c, color (optional) – Controls the line width and edge color for both the colorbar outline and the level dividers.
edgefix (
boolorfloat, default:rc.edgefix=True) – Whether to fix the common issue where white lines appear between adjacent patches in saved vector graphics (this can slow down figure rendering). See this github repo for a demonstration of the problem. IfTrue, a small default linewidth of0.3is used to cover up the white lines. If float (e.g.edgefix=0.5), this specific linewidth is used to cover up the white lines. This feature is automatically disabled when the patches have transparency.rasterize (
bool, default:rc['colorbar.rasterize']=False) – Whether to rasterize the colorbar solids. The matplotlib default wasTruebut proplot changes this toFalsesince rasterization can cause misalignment between the color patches and the colorbar outline.**kwargs – Passed to
colorbar.