pltutils¶
Collection of utility functions for matplotlib
Functions
|
|
|
|
|
|
|
|
|
Adjust the axis length to include a margin (after autoscale) |
|
Return text alignment based on (x, y) numbers |
|
Annotate with a box around the text |
|
A context manager that sets the active Axes instance to |
|
Change the backend within this context |
|
Blend color with background |
|
Convert from centimeter to inch |
|
Custom colorbar with modified style and optional label |
|
Remove the top and right spines |
|
Remove all spines, axes labels and ticks |
|
Colormap with direct mapping: data[i] -> colors[i] |
|
Get a color palette from matplotlib's colormap database |
|
Custom legend with modified style and option to reverse label order |
|
Function to plot the values as changing colors in a plot. |
|
Visualize vectors, alternative to plt.quiver() |
|
Redraw all spines, opposite of |
|
Set minimum axis length |
|
Set minimum ratio between axes limits |
|
Set the active color palette |
|
Shortcut for |
- cm2inch(*values) Tuple[int, int] ¶
Convert from centimeter to inch
- Parameters:
- *values
- Returns:
- tuple
Examples
>>> cm2inch(2.54, 5.08) (1.0, 2.0)
- colorbar(mappable: ScalarMappable | None = None, ax: Axes | None = None, cax: Axes | None = None, label='', powerlimits=(0, 0), **kwargs)¶
Custom colorbar with modified style and optional label
Changes default
pad
andaspect
argument values and turns on rasterization for a nicer looking colorbar with smaller size in vector formats (pdf, svg).- Parameters:
- mappableOptional[ScalarMappable]
The image or contour set over which the colorbar will be drawn.
- axOptional[plt.Axes]
Axis to add the colorbar to.
- caxOptional[plt.Axes]
Axis to draw the colorbar in.
- labelstr
Color data label.
- powerlimitsTuple[int, int]
Sets size thresholds for scientific notation.
- **kwargs
Forwarded to
matplotlib.pyplot.colorbar()
.
- despine(trim: bool = False, ax: Axes | None = None) None ¶
Remove the top and right spines
- Parameters:
- trimbool
Trim spines so that they don’t extend beyond the last major ticks.
- axOptional[plt.Axes]
Axes to despine.
- despine_all(ax: Axes | None = None) None ¶
Remove all spines, axes labels and ticks
- Parameters:
- axOptional[plt.Axes]
Axes to despine.
- get_palette(name=None, num_colors=8, start=0)¶
Get a color palette from matplotlib’s colormap database
- Parameters:
- namestr, optional
Name of the palette to get. If
None
, get the active palette.- num_colorsint
Number of colors to retrieve.
- startint
Staring from this color number.
- Returns:
- List[color]
- legend(*args, reverse=False, facecolor='0.98', lw=0, ax: Axes | None = None, **kwargs)¶
Custom legend with modified style and option to reverse label order
- Parameters:
- reversebool
Reverse the label order.
- facecolorcolor
Legend background color.
- lwfloat
Frame width.
- axOptional[plt.Axes]
Axis to add the legend to.
- *args, **kwargs
Forwarded to
matplotlib.pyplot.legend()
.
- respine(ax: Axes | None = None) None ¶
Redraw all spines, opposite of
despine()
- Parameters:
- axOptional[plt.Axes]
Axes to respine.
- set_palette(name=None, num_colors=8, start=0, ax: Axes | None = None)¶
Set the active color palette
- Parameters:
- namestr, optional
Name of the palette. If
None
, modify the active palette.- num_colorsint
Number of colors to retrieve.
- startint
Staring from this color number.
- axOptional[plt.Axes]
Axis to set the palette to.
- use_style(style=pb_style)¶
Shortcut for
matplotlib.style.use()
with pybinding style applied by default- Parameters:
- styledict
A matplotlib style specification.