plotlive.pyplot
State-machine API — mirrors matplotlib.pyplot. Every function operates on the current figure and axes, created automatically on first use.
Figure management
figure(num=None, figsize=(6.4, 4.8), dpi=100, facecolor='white', edgecolor='white', **kwargs)
Create a new figure and make it current.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
figsize
|
Width and height in inches. Default is |
(6.4, 4.8)
|
|
facecolor
|
Background colour. Default is |
'white'
|
Returns:
| Type | Description |
|---|---|
Figure
|
The new |
subplots(nrows=1, ncols=1, squeeze=True, figsize=(6.4, 4.8), sharex=False, sharey=False, **kwargs)
Create a figure with a grid of subplots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nrows
|
Number of rows. Default is |
1
|
|
ncols
|
Number of columns. Default is |
1
|
|
squeeze
|
If |
True
|
|
figsize
|
Width and height in inches. |
(6.4, 4.8)
|
Returns:
| Type | Description |
|---|---|
|
Tuple of |
|
|
a 1×1 grid, a 1-D ndarray for a single row/column, or a 2-D ndarray |
|
|
otherwise — matching matplotlib's squeeze behaviour. |
gcf()
Return the current figure, creating one if none exists.
gca(**kwargs)
Return the current axes, creating one if none exists.
clf()
Clear the current figure — removes all axes and the suptitle.
cla()
Clear the current axes — removes all artists and resets axis state.
close(fig=None)
Remove fig (or the current figure) from the figure list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure to close. Defaults to the current figure. |
None
|
show(block=True)
Open pygame window (non-Jupyter) or display inline (Jupyter notebook).
savefig(fname, **kwargs)
Save the current figure to fname (PNG, based on extension).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fname
|
str
|
Output file path, e.g. |
required |
tight_layout(**kwargs)
Adjust subplot spacing to prevent label overlap.
suptitle(t, **kwargs)
Set a centred title for the whole figure (above all subplots).
Plots
plot(*args, **kwargs)
Plot lines and/or markers on the current axes.
Accepts the same arguments as matplotlib.pyplot.plot, including
format strings ('r--', 'bo-') and keyword arguments
(color, linewidth, label, …).
Returns:
| Type | Description |
|---|---|
|
List of |
scatter(x, y, **kwargs)
Plot a scatter of points on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
X coordinates. |
required | |
y
|
Y coordinates. |
required | |
c
|
Colour(s) or array of values mapped through cmap. |
required | |
s
|
Marker size(s) in points². |
required | |
cmap
|
Colormap name. Default is |
required | |
alpha
|
Opacity, 0–1. |
required |
Returns:
| Type | Description |
|---|---|
|
|
hist(x, **kwargs)
Plot a histogram on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Data array. |
required | |
bins
|
Number of bins or bin edges. Default is |
required | |
color
|
Bar fill colour. |
required | |
edgecolor
|
Bar edge colour. |
required |
Returns:
| Type | Description |
|---|---|
|
Tuple of |
bar(x, height, **kwargs)
Plot vertical bars on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Bar positions. |
required | |
height
|
Bar heights. |
required |
Returns:
| Type | Description |
|---|---|
|
|
barh(y, width, **kwargs)
Plot horizontal bars on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Bar positions. |
required | |
width
|
Bar widths. |
required |
Returns:
| Type | Description |
|---|---|
|
|
imshow(X, **kwargs)
Display an image or 2-D array on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
2-D array |
required | |
cmap
|
Colormap name for scalar arrays. Default is |
required | |
vmin
|
Lower clamp value for colormap scaling. |
required | |
vmax
|
Upper clamp value for colormap scaling. |
required | |
origin
|
|
required |
Returns:
| Type | Description |
|---|---|
|
|
colorbar(mappable=None, ax=None, **kwargs)
Draw a colour scale bar next to an image plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mappable
|
The |
None
|
|
ax
|
Target axes. Defaults to the current axes. |
None
|
fill_between(x, y1, y2=0, **kwargs)
Fill the area between two horizontal curves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
X coordinates. |
required | |
y1
|
Upper (or first) curve values. |
required | |
y2
|
Lower (or second) curve values. Default is |
0
|
|
alpha
|
Opacity. Default is |
required |
errorbar(x, y, **kwargs)
Plot points with error bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
X positions. |
required | |
y
|
Y positions. |
required | |
yerr
|
Y error values (symmetric scalar, array, or |
required | |
xerr
|
X error values. |
required | |
fmt
|
Format string for the data points. Default is |
required | |
capsize
|
Length of error bar caps in points. |
required |
boxplot(data, **kwargs)
Draw a box-and-whisker plot for one or more datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array or list of arrays. Each array is one box. |
required | |
labels
|
Tick labels for each box. |
required |
violinplot(data, **kwargs)
Draw a violin plot for one or more datasets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array or list of arrays. |
required | |
positions
|
X positions for each violin. Default is |
required | |
widths
|
Width of each violin. Default is |
required |
pie(x, **kwargs)
Draw a pie chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Wedge sizes (need not sum to 1; normalised automatically). |
required | |
labels
|
Sequence of wedge labels. |
required | |
startangle
|
Starting angle in degrees, counter-clockwise from x-axis. |
required |
stackplot(x, *ys, **kwargs)
Draw a stacked area chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
X coordinates shared by all series. |
required | |
*ys
|
One array per series. |
()
|
|
labels
|
Legend labels for each series. |
required | |
alpha
|
Opacity. Default is |
required |
Axis decoration
xlabel(s, **kwargs)
Set the x-axis label on the current axes.
ylabel(s, **kwargs)
Set the y-axis label on the current axes.
title(s, **kwargs)
Set the title on the current axes.
legend(*args, **kwargs)
Add a legend to the current axes using labelled artists.
grid(visible=True, **kwargs)
Show or hide the grid on the current axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visible
|
|
True
|
xlim(*args, **kwargs)
Get or set the x-axis limits of the current axes.
Call with no arguments to get the current limits, or pass
(left, right) to set them.
Returns:
| Type | Description |
|---|---|
|
|
ylim(*args, **kwargs)
Get or set the y-axis limits of the current axes.
Call with no arguments to get the current limits, or pass
(bottom, top) to set them.
Returns:
| Type | Description |
|---|---|
|
|
xscale(value, **kwargs)
Set the x-axis scale. Use 'log' for logarithmic scale.
yscale(value, **kwargs)
Set the y-axis scale. Use 'log' for logarithmic scale.
xticks(ticks=None, labels=None, **kwargs)
Get or set x-axis tick positions and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ticks
|
Tick positions. If |
None
|
|
labels
|
Tick labels. Defaults to string representation of ticks. |
None
|
yticks(ticks=None, labels=None, **kwargs)
Get or set y-axis tick positions and labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ticks
|
Tick positions. If |
None
|
|
labels
|
Tick labels. Defaults to string representation of ticks. |
None
|
axhline(y=0, xmin=0, xmax=1, **kwargs)
Draw a horizontal line across the current axes at y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Data-space y position. Default is |
0
|
|
xmin
|
Left extent in axes fraction (0–1). Default is |
0
|
|
xmax
|
Right extent in axes fraction (0–1). Default is |
1
|
axvline(x=0, ymin=0, ymax=1, **kwargs)
Draw a vertical line across the current axes at x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Data-space x position. Default is |
0
|
|
ymin
|
Bottom extent in axes fraction (0–1). Default is |
0
|
|
ymax
|
Top extent in axes fraction (0–1). Default is |
1
|
Animation
animate(update_fn, frames=None, interval=200, repeat=True, fig=None, fargs=None, save_count=None)
Create and register an animation on the current figure.
Shorthand for constructing a ~plotlive.animation.FuncAnimation and
attaching it to the figure. For the full parameter set, construct
~plotlive.animation.FuncAnimation directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_fn
|
Called as |
required | |
frames
|
Number of frames (int), explicit frame values (list), a
generator, or |
None
|
|
interval
|
int
|
Milliseconds between frames. Default is |
200
|
repeat
|
bool
|
Loop when finished. Default is |
True
|
fig
|
Figure | None
|
Figure to attach to. Defaults to the current figure. |
None
|
fargs
|
Extra positional arguments forwarded to update_fn. |
None
|
|
save_count
|
int | None
|
Frame count when frames is |
None
|
Returns:
| Type | Description |
|---|---|
FuncAnimation
|
The registered |
save_animation(filename, fps=None, fig=None)
Export the current figure's animation to a file.
Renders all frames off-screen — no window opens. Resets to frame 0
afterwards so a subsequent show() starts from the beginning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output path. Extension determines format:
|
required |
fps
|
int | None
|
Frames per second. Defaults to |
None
|
fig
|
Figure | None
|
Figure to export. Defaults to the current figure. |
None
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no animation has been registered on the figure. |