Figure.colorbar¶
- Figure.colorbar(**kwargs)[source]¶
Add a colorbar along the side of the figure.
- 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.length (
float, default:rc['colorbar.length']=1.0) – The colorbar length. Units are relative to the span of the rows and columns of subplots.shrink (
float, optional) – Alias forlength. This is included for consistency withmatplotlib.figure.Figure.colorbar.width (
unit-spec, default:rc['colorbar.width']=0.2) – The colorbar width. If float, units are inches. If string, interpreted byunits.loc (
str, optional) – The colorbar location. Valid location keys are as follows.Location
Valid keys
left
'left','l'right
'right','r'bottom
'bottom','b'top
'top','t'space (
floatorstr, default:None) – The fixed space between the colorbar and the subplot grid 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 (
floatorstr, default:rc['subplots.innerpad']=1.0orrc['subplots.panelpad']=0.5) – The tight layout padding between the colorbar and the subplot grid. Default isrc['subplots.innerpad']for the first colorbar andrc['subplots.panelpad']for subsequently “stacked” colorbars. If float, units are em-widths. If string, interpreted byunits.row, rows – Aliases for
spanfor colorbars on the left or right side.col, cols – Aliases for
spanfor colorbars on the top or bottom side.span (
intor2-tupleofint, default:None) – Integer(s) indicating the span of the colorbar across rows and columns of subplots. For example,fig.colorbar(loc='b', col=1)draws a colorbar beneath the leftmost column of subplots, andfig.colorbar(loc='b', cols=(1, 2))draws a colorbar beneath the left two columns of subplots. By default the colorbar will span every subplot row and column.align (
{'center', 'top', 't', 'bottom', 'b', 'left', 'l', 'right', '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.