legendkit.colorart¶
- class legendkit.colorart(mappable=None, cmap=None, norm=None, *, ax: Axes = None, alpha=None, values=None, boundaries=None, flip=False, spacing='uniform', orientation='vertical', ticks=None, format=None, tick_width=1, tick_size=0.25, tick_color='white', ticklabel_loc='auto', ticklocation='both', width: float = None, height: float = None, borderpad: float = None, textpad: float = None, borderaxespad: float = None, prop=None, fontsize=None, title=None, title_fontsize=None, title_fontproperties=None, alignment='left', loc=None, deviation=0.05, bbox_to_anchor=None, bbox_transform=None, rasterized=True)¶
Axes-independent colorbar
Most of the time, it’s safe to use
colorart()as a drop-in replacement forcolorbar().- Parameters:
- mappable
ScalarMapping The mappable whose colormap and norm will be used.
- norm
Normalize The normalization to use.
- cmap
Colormap The colormap to use.
- ax
Axes The axes to draw colorbar.
- alphafloat
Control the transparency
- values
- boundaries
- flipbool
Flip the colorart so the colormap is reversed visually (low values at top for vertical, right for horizontal).
- orientation{‘vertical’, ‘horizontal’}
The orientation of colorart.
- tickslist of ticks or Locator
- formatstr or Formatter
- tick_widthfloat
The width of tick.
- tick_sizefloat
The length of tick.
- tick_colorcolor
The color of tick.
- ticklocation{‘both’, ‘left’, ‘right’, ‘top’, ‘bottom’}
The location of the colorbar ticks.
- widthfloat
The width of colorart
- heightfloat
The height of colorart
- borderpadfloat, default: rcParams[“legend.borderpad”]
The fractional whitespace inside the colorart border, in font-size units.
- textpadfloat, default: rcParams[“legend.handletextpad”]
The space between label and the colorart
- borderaxespadfloat, default: rcParams[“legend.borderaxespad”]
The pad between the axes and colorart border, in font-size units.
- prop
FontProperties The font properties of the colorart.
- fontsizefloat
The fontsize
- titlestr
The title of colorart
- title_fontsizefloat
The fontsize of title
- title_fontproperties
FontProperties The fontproperties of title
- alignment{‘center’, ‘left’, ‘right’}, default: ‘center’
The alignment of the colorart and title.
- locstr
Apart from the default location code, you can add ‘out’ as prefix to place the legend ouside the axes. See all available options.
- deviationfloat
The space between colorbar and axes if place outside
- bbox_to_anchor
- bbox_transform
- rasterizedbool
Whether to rasterize the colorart, reduce file size in vectorized backend.
- mappable
Examples
>>> from legendkit import colorart >>> data = np.random.rand(10, 10) >>> mp = plt.pcolormesh(data, cmap="RdBu") >>> colorart(mp)