A few conveniences for working with matplotlib.
Project description
A few conveniences for working with matplotlib.
Latest release 20230407: FigureSize: get defaults via $FIGURE_SIZE_DX, $FIGURE_SIZE_DY and $FIGURE_SIZE_DPI envvars.
Function axes(figure=None, ax=None, **fig_kw) -> matplotlib.axes._axes.Axes
Return a set of Axes
.
Parameters:
figure
: optionalFigure
from which to obtain theAxes
or an(x,y)
figure size or an(x,y,dpi)
figure sizeax
: optionalAxes
or axes index
If ax
is already an Axes
it is returned unchanged.
Otherwise ax
should be the index of a set of axes,
default 0
.
If figure
is a Figure
, ax
is used to select one of its
sets of axes.
Otherwise a Figure
is created and a set of axes is selected.
The default figure size comes from the FigureSize
defaults.
The figure
positional parameter may be supplied
as a 2-tuple (fig_dx,fig_dy)
to override the default size
or as a 3-tuple (fig_dx,fig_dy,dpi)
to override the default size and dpi,
or as a FigureSze
.
Class FigureSize
Specifications for a Figure
's dimensions.
Function print_figure(figure_or_ax, imgformat=None, file=None)
Print figure_or_ax
to a file.
Parameters:
figure_or_ax
: amatplotlib.figure.Figure
or an object with a.figure
attribute such as a set ofAxes
imgformat
: optional output format; if omitted use'sixel'
iffile
is a terminal, otherwise'png'
file
: the output file, defaultsys.stdout
Function remove_decorations(figure_or_ax: Union[matplotlib.figure.Figure, matplotlib.axes._axes.Axes])
Remove all decorations from a Figure
or Axes
instance,
intended for making bare plots such as a tile in GUI.
Presently this removes:
- axes markings and legend from each axis
- the padding from all the figure subplots
Function save_figure(figure_or_ax, imgpath: str, force=False)
Save a Figure
to the file imgpath
.
Parameters:
figure_or_ax
: amatplotlib.figure.Figure
or an object with a.figure
attribute such as a set ofAxes
imgpath
: the filesystem path to which to save the imageforce
: optional flag, defaultFalse
: if true theimgpath
will be written to even if it exists
Function saved_figure(figure_or_ax, dir=None, ext=None)
Context manager to save a Figure
to a file and yield the file path.
Parameters:
figure_or_ax
: amatplotlib.figure.Figure
or an object with a.figure
attribute such as a set ofAxes
dir
: passed totempfile.TemporaryDirectory
ext
: optional file extension, default'png'
Release Log
Release 20230407: FigureSize: get defaults via $FIGURE_SIZE_DX, $FIGURE_SIZE_DY and $FIGURE_SIZE_DPI envvars.
Release 20220918:
- New FigureSize class.
- axes(): accept a FigureSize for figure.
Release 20220805: Initial PyPI release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cs.mplutils-20230407-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02434ba7bd34eb1eb9e295e707af29c09526b55cf789cd6664f5c4d876b9c9a3 |
|
MD5 | bfb2c2be5a131c797e8993c7cadba297 |
|
BLAKE2b-256 | e54ed94b674d2f87df736964ae726dbf59d0ed11e7a77cc21946897271c44b82 |