Figure & Axes¶
The core 2D/3D plotting API.
Entry points¶
subplots
¶
subplots(
nrows: int = 1,
ncols: int = 1,
*,
figsize: tuple[float, float] = DEFAULT_FIGSIZE,
sharex: bool = False,
sharey: bool = False,
projection: str | None = None,
theme=None,
units: str = "pt",
width_ratios=None,
height_ratios=None
)
Create a [Figure] with an nrows x ncols grid of axes.
figsize is the canvas (width, height) in points by default, so a
plot is sized directly against its font scale; pass units="in", "cm"
or "mm" for another unit. projection="3d" makes every axes an
[Axes3D]. theme is a [Theme] (or a preset name — "default",
"dark", "grayscale"); it flows to every axes. Returns
(fig, ax) for a 1x1 grid, (fig, [ax, ...]) when one dimension is 1,
and (fig, [[ax, ...], ...]) otherwise (row-major).
width_ratios / height_ratios give relative column widths and row
heights, e.g. width_ratios=[2, 1] for a wide panel beside a narrow one.
Only the proportions matter ([2, 1] and [0.5, 0.25] are the same),
and the gutters stay a fixed size - weighting changes the panels, not the
space between them.
Source code in python/pyplotrs/_figure.py
subplot_mosaic
¶
subplot_mosaic(
mosaic,
*,
figsize: tuple[float, float] = DEFAULT_FIGSIZE,
theme=None,
units: str = "pt"
)
Build a figure of spanning axes from an ASCII mosaic layout.
mosaic is a multi-line string (or a list of equal-length rows) whose
repeated labels mark the cells each axes spans, e.g.::
"""
AB
AC
"""
gives A spanning both rows of column 0, with B/C stacked at the
right. "." (or a space) marks an empty cell. Returns
(fig, {label: axes}). Each label's cells must form a solid rectangle.
The string is dedented before it is read, so the indented triple-quoted form above - the way a mosaic is actually written inside a function - means what it looks like. Without that, the shared leading spaces are cells of their own and the layout gains a phantom panel wider than the real ones.
Source code in python/pyplotrs/_figure.py
figure
¶
figure(
figsize: tuple[float, float] = DEFAULT_FIGSIZE,
*,
theme=None,
units: str = "pt"
) -> Figure
Create an empty Figure (no axes). Use
Figure.add_gridspec + Figure.add_subplot to place spanning
axes, or subplots / subplot_mosaic for the common cases.
Source code in python/pyplotrs/__init__.py
Figure¶
Figure
¶
Figure(
figsize: tuple[float, float] = DEFAULT_FIGSIZE,
nrows: int = 1,
ncols: int = 1,
sharex: bool = False,
sharey: bool = False,
projection: str | None = None,
theme=None,
units: str = "pt",
width_ratios=None,
height_ratios=None,
)
A figure: an output canvas holding a grid of [Axes].
figsize is the (width, height) of the canvas in points by default
(units="pt"). Sizing in points lets you reason about a plot directly
against its font scale — e.g. the default 250x200 pt figure with a 10 pt
font. That default is a single journal column wide (~3.5 in), so a figure
comes out at publication size instead of needing to be scaled down to one.
Pass units="in", "cm" or "mm" to give the size in another unit
(Nature's widths are 89 mm / 183 mm).
Source code in python/pyplotrs/_figure.py
set
¶
add_gridspec
¶
Switch this figure to spanning-subplot mode over an nrows x
ncols grid and return a GridSpec. Populate it with
add_subplot; existing auto-created axes are cleared.
width_ratios/height_ratios weight the columns and rows (see
subplots).
Source code in python/pyplotrs/_figure.py
add_subplot
¶
Add an axes at a GridSpec slice (e.g. gs[0, :] or
gs[1:, 0]). Returns the new axes.
Source code in python/pyplotrs/_figure.py
legend
¶
legend(
*,
loc: str = "right",
ncol: int = 1,
title: str | None = None,
frameon: bool = True,
fontsize: float | None = None
) -> "Figure"
Enable a single figure-level legend, collecting the labeled marks of
every axes into one box placed in a reserved column to the right of the
grid. Unlike Axes.legend, this is laid out as its own region and
so can never overlap the data. loc currently supports "right".
ncol/title/frameon/fontsize work as on
Axes.legend; the reserved column is measured from them, so a
two-column figure legend takes a wider, shorter band.
Source code in python/pyplotrs/_figure.py
colorbar
¶
colorbar(
mappable: "Mappable",
*,
label: str | None = None,
orientation: str = "vertical",
shrink: float = 1.0,
ticks=None,
format=None
) -> "Figure"
Attach a colorbar for mappable (from Axes.imshow or a
colormapped Axes.scatter) in a reserved band beside its axes.
The tick scale follows the mappable's norm (e.g. log ticks for
a LogNorm).
orientation="horizontal" puts the bar beneath the plot instead, in
its own reserved band below the x-axis label. shrink scales the
strip's length as a fraction of the plot extent, centered. ticks
pins the tick values and format accepts anything
pyplotrs.ticker does - a formatter, a "{x:.2f}" template, or
a callable.
Source code in python/pyplotrs/_figure.py
save
¶
save(
path: str,
*,
dpi: float = 200.0,
tagged: bool = False,
transparent: bool = False,
title: str | None = None,
alt: str | None = None
) -> None
Save to path; the format is inferred from the extension
(.pdf, .svg, .png, or .html/.htm).
transparent=True drops the page behind the figure, in favor of an
alpha channel. That means two things at once: the white fill .png
would otherwise paint, and — for a theme that states a page of its own,
such as themes.dark — that fill too, in every
format. A dark figure saved this way keeps its light text and rules but
carries no background, ready to composite onto whatever is behind it.
.pdf/.svg/.html under a theme with no stated page paint no
background to begin with, so for them the flag changes nothing.
.html writes a single self-contained page with the figure inlined as
vector SVG (real selectable text, embedded fonts, nothing fetched at view
time) — handy for dropping a chart straight into a web page or report.
If any label contains $...$ math, that math is re-rendered by an
inlined copy of MathJax (SVG output) so it is selectable and copyable
as LaTeX/MathML (right-click → Show Math As); the page stays fully
offline. For a 3D figure the .html is instead a dependency-free
Canvas2D viewer you can orbit (drag), zoom (scroll) and pan (shift-drag).
dpi controls the resolution of raster (.png) output and is
recorded in the file's physical-size metadata. PDF, SVG and HTML pages
are resolution-independent, but any image inside one - a heatmap,
a filled contour - is not, and dpi sets its resolution there too.
That matters for a journal: an image embedded at the 200 dpi default
is below most submission minimums, and pinning it there regardless of
what was asked for meant a 600-dpi PDF carried a third of the detail a
600-dpi PNG of the same figure did.
tagged=True (.pdf only) writes a tagged, accessible PDF: the
whole chart becomes one Figure structure element with alt text
(auto-derived from the titles/labels when omitted) so screen readers can
announce it, plus a document title and language. For .html the
same auto-derived title/alt label the page and the inline SVG
(role="img"), and title/alt may be overridden here too.
Source code in python/pyplotrs/_figure.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
GridSpec
¶
A lightweight grid geometry for spanning subplots. Create with a figure's
row/column count, then slice it (NumPy-style) to place an axes across a
range of rows/columns via Figure.add_subplot.
Source code in python/pyplotrs/_figure.py
Axes¶
Axes
¶
Bases: _AxesBase
A single set of axes: a coordinate system plus a stack of marks.
Source code in python/pyplotrs/axes.py
line
¶
line(
xs,
ys,
*,
label: str | None = None,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
linestyle: str = "solid",
marker: str | None = None,
markersize: float = 5.0,
simplify: bool = True,
zorder: float = 0.0
) -> "Axes"
Plot a polyline through (xs, ys).
color may be None (cycle the palette), "C0".."C7", or an
(r, g, b[, a]) tuple. linestyle is one of solid/dashed/
dotted/dashdot (or none for markers only). An optional
marker draws a glyph at each vertex.
simplify (default True) collapses runs of near-collinear
vertices in device space - visually identical output, far smaller and
faster vector export on dense data. Set False to keep every vertex
exactly (e.g. when the polyline is the data being exported).
Source code in python/pyplotrs/axes.py
scatter
¶
scatter(
xs,
ys,
*,
label: str | None = None,
color=None,
markersize: float | None = None,
alpha: float = 1.0,
marker: str = "o",
edgecolor=None,
edgewidth: float = 1.0,
size: float | None = None,
c=None,
cmap="viridis",
norm=None,
vmin: float | None = None,
vmax: float | None = None,
zorder: float = 0.0
)
Scatter markers at (xs, ys).
markersize is the marker diameter in points, the same unit every
other mark uses. size is accepted for matplotlib compatibility and
means area in pt² (so size=36 and markersize=6 agree).
Pass c (a per-point array) to color markers by value through cmap
and norm (vmin/vmax set the range; norm="log" or a
pyplotrs.norms instance for non-linear). Returns a colorbar handle
in that case, else self.
Source code in python/pyplotrs/axes.py
bar
¶
bar(
x,
height,
*,
width: float = 0.5,
bottom=0.0,
color=None,
alpha: float = 1.0,
label: str | None = None,
edgecolor=None,
zorder: float = 0.0
) -> "Axes"
Draw vertical bars of the given height at positions x. x
may be strings (categories), which set a categorical x-axis.
width is a data extent in x units, not a stroke width: at the
default 0.5 a bar fills half the gap to its neighbor. This is narrower
than matplotlib's 0.8 on purpose - the gap is what makes bars read as
discrete categories at the default single-column figure size.
Source code in python/pyplotrs/axes.py
barh
¶
barh(
y,
width,
*,
height: float = 0.8,
left=0.0,
color=None,
alpha: float = 1.0,
label: str | None = None,
edgecolor=None,
zorder: float = 0.0
) -> "Axes"
Horizontal bars of the given width at vertical positions y.
y may be strings (categories), which set a categorical y-axis.
Source code in python/pyplotrs/axes.py
hist
¶
hist(
data,
*,
bins: int = 10,
color=None,
alpha: float = 1.0,
label: str | None = None,
range=None,
density: bool = False,
zorder: float = 0.0
) -> "Axes"
Bin data into bins equal-width bins and draw the histogram.
The binning loop runs in Rust (_core.histogram), matching what
hist2d already did.
Source code in python/pyplotrs/axes.py
boxplot
¶
boxplot(
data,
*,
positions=None,
widths: float = 0.5,
color=None,
showfliers: bool = True,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Box-and-whisker plot. data is a list of numeric arrays (one box
each); positions default to 1..n.
Source code in python/pyplotrs/axes.py
violinplot
¶
violinplot(
data,
*,
positions=None,
widths: float = 0.5,
color=None,
points: int = 128,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Violin plot: a mirrored Gaussian-KDE density for each array in
data (KDE computed in Rust, no SciPy dependency).
Source code in python/pyplotrs/axes.py
pie
¶
pie(
sizes,
*,
labels=None,
colors=None,
startangle: float = 90.0,
radius: float = 1.0,
alpha: float = 1.0,
zorder: float = 0.0
) -> "Axes"
Pie chart of sizes (auto-normalized). Turns the frame off and fixes
an equal aspect so wedges stay circular.
This is the one mark with no scalar label: its labels are per-wedge,
so they come from labels - which is also what feeds legend.
Source code in python/pyplotrs/axes.py
fill_between
¶
fill_between(
xs,
y1,
y2=0.0,
*,
color=None,
alpha: float = 0.3,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Fill the band between y1 and y2 across xs.
Source code in python/pyplotrs/axes.py
fill_betweenx
¶
fill_betweenx(
ys,
x1,
x2=0.0,
*,
color=None,
alpha: float = 0.3,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Fill the band between x1 and x2 across ys - the transpose
of fill_between, for bands around a horizontal profile.
Source code in python/pyplotrs/axes.py
errorbar
¶
errorbar(
xs,
ys,
*,
yerr=None,
xerr=None,
color=None,
label: str | None = None,
marker: str | None = "o",
markersize: float = 5.0,
linewidth: float | None = None,
alpha: float = 1.0,
capsize: float = 3.0,
linestyle: str = "solid",
zorder: float = 0.0
) -> "Axes"
Plot (xs, ys) with symmetric yerr/xerr error bars.
Source code in python/pyplotrs/axes.py
step
¶
step(
xs,
ys,
*,
where: str = "pre",
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
linestyle: str = "solid",
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Step plot through (xs, ys); where is pre/post/mid.
Source code in python/pyplotrs/axes.py
stairs
¶
stairs(
values,
edges=None,
*,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
fill: bool = False,
baseline: float = 0.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Step outline of values over bin edges (len(values)+1 edges;
defaults to 0..n). fill=True fills down to baseline.
Source code in python/pyplotrs/axes.py
stem
¶
stem(
xs,
ys,
*,
bottom: float = 0.0,
color=None,
alpha: float = 1.0,
marker: str = "o",
markersize: float = 5.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Stem plot: a vertical line from bottom to each (x, y) topped by
a marker, with a baseline.
Source code in python/pyplotrs/axes.py
broken_barh
¶
broken_barh(
xranges,
yrange,
*,
color=None,
edgecolor=None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Horizontal bars from (xstart, width) pairs, all spanning the
vertical yrange = (ymin, height) (e.g. Gantt / interval plots).
Source code in python/pyplotrs/axes.py
eventplot
¶
eventplot(
positions,
*,
orientation: str = "horizontal",
lineoffsets: float = 1.0,
linelengths: float = 0.8,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Raster of event marks. positions is a 1D array or a list of rows;
each row is offset by lineoffsets and drawn linelengths long
(perpendicular to orientation).
Source code in python/pyplotrs/axes.py
stackplot
¶
stackplot(
x,
*ys,
labels=None,
colors=None,
alpha: float = 1.0,
baseline: float = 0.0,
zorder: float = 0.0
) -> "Axes"
Stacked area plot: each series in ys is filled on top of the
cumulative total of the ones before it.
ys may be passed as separate arrays or as one sequence of arrays,
matching stackplot(x, a, b) and stackplot(x, [a, b]).
Source code in python/pyplotrs/axes.py
imshow
¶
imshow(
data,
*,
cmap="viridis",
vmin: float | None = None,
vmax: float | None = None,
norm=None,
extent=None,
origin: str = "upper",
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Mappable"
Display 2D data as a colormapped image.
data is a sequence of equal-length rows. cmap is a colormap
name (see pyplotrs.colormaps) or a Colormap. norm maps
values onto the color axis (None linear, "log" for a
LogNorm, or any Normalize);
the per-pixel lookup runs in Rust. extent is (x0, x1, y0, y1) in
data coordinates (default (0, ncols, 0, nrows)); origin is
"upper" (row 0 at top) or "lower". Returns a handle for
Figure.colorbar.
Source code in python/pyplotrs/axes.py
matshow
¶
Display a matrix with row 0 at the top and one cell per entry.
imshow with the conventions a matrix wants rather than the
ones an image wants: origin at the top-left and an equal aspect, so
cells stay square.
Source code in python/pyplotrs/axes.py
spy
¶
spy(
data,
*,
markersize: float = 4.0,
color=None,
marker: str = "s",
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Plot the sparsity pattern of data: a marker wherever an entry is
nonzero, row 0 at the top.
Source code in python/pyplotrs/axes.py
pcolormesh
¶
pcolormesh(
*args,
cmap="viridis",
norm=None,
vmin: float | None = None,
vmax: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Mappable"
Pseudocolor plot of a 2D grid: pcolormesh(C) or
pcolormesh(X, Y, C). Regular grids route to the fast Rust image path;
irregular grids draw one colored quad per cell.
Source code in python/pyplotrs/axes.py
pcolor
¶
Alias of pcolormesh.
matplotlib distinguishes the two (pcolor returns a masked-aware
PolyCollection, pcolormesh a faster QuadMesh); pyplotrs has
only the fast path, and it already chooses per-cell quads over the
image path whenever the grid is irregular, so the distinction has
nothing left to express.
Source code in python/pyplotrs/axes.py
hist2d
¶
hist2d(
xs,
ys,
*,
bins=10,
range=None,
cmap="viridis",
norm=None,
vmin: float | None = None,
vmax: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Mappable"
2D histogram of (xs, ys) rendered as a colormapped image. bins
is an int or (nx, ny); the count grid is built in Rust.
Source code in python/pyplotrs/axes.py
hexbin
¶
hexbin(
xs,
ys,
*,
gridsize: int = 30,
cmap="viridis",
norm=None,
vmin: float | None = None,
vmax: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Mappable"
Hexagonal binning of (xs, ys) colored by count (binning in Rust).
The whole lattice is drawn, as in matplotlib: a cell no point landed in is a count of zero, so it takes the bottom of the colormap rather than leaving the background showing through.
Source code in python/pyplotrs/axes.py
contour
¶
contour(
*args,
levels=None,
colors=None,
cmap=None,
linewidth: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Contour lines of a 2D field: contour(Z) or contour(X, Y, Z).
Marching squares runs in Rust; lines are colored per level from
colors (a single color / list) or cmap (default palette C0).
levels is either the thresholds themselves, or an int asking for
about that many: the levels then land on round numbers inside the data
range, the way the axis locator picks ticks, so the count comes out near
the hint rather than exactly on it.
Source code in python/pyplotrs/axes.py
contourf
¶
contourf(
*args,
levels=None,
cmap="viridis",
norm=None,
vmin: float | None = None,
vmax: float | None = None,
upsample: int = 6,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Mappable"
Filled contour bands of a 2D field. The field is bilinearly upsampled
and band-colored in Rust (a raster fill, like imshow).
levels is either the band edges themselves, or an int asking for
about that many bands. Auto edges are the round numbers
contour draws its lines on, extended out to bracket the data, so
a contour overlay lands exactly on the band boundaries - and the
colorbar spans those round numbers rather than the raw extrema.
Source code in python/pyplotrs/axes.py
quiver
¶
quiver(
x,
y,
u,
v,
*,
scale: float = 1.0,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Arrow field: an arrow at each (x, y) pointing along (u, v).
scale multiplies the vectors in data space (so the arrow tip lands
at x + u*scale), and the arrowheads are sized in points. x/y
may be 1D lists or 2D grids, as long as all four agree in shape.
Source code in python/pyplotrs/axes.py
streamplot
¶
streamplot(
x,
y,
u,
v,
*,
density: float = 1.0,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
maxlength: float = 4.0,
arrows: bool = True,
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Streamlines of the vector field (u, v) sampled on the grid
(x, y).
x/y are the 1D coordinates of the grid columns/rows and
u/v are 2D len(y) x len(x) grids. Seeds are laid on a
density-scaled lattice and integrated both ways with RK4;
maxlength caps each streamline's arc length in grid cells.
arrows puts a direction head at each streamline's midpoint - a
streamline is otherwise unsigned, and which way the flow runs is
usually the point of drawing one.
Source code in python/pyplotrs/axes.py
loglog
¶
semilogx
¶
line with the x-axis log-scaled - matplotlib's ax.semilogx.
A thin wrapper: ax.set(xscale="log") then ax.line(xs, ys, **kwargs).
Source code in python/pyplotrs/axes.py
semilogy
¶
hlines
¶
hlines(
y,
xmin,
xmax,
*,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
linestyle: str = "solid",
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Horizontal line segments at each y, spanning xmin to xmax
in data coordinates.
Unlike axhline, which spans a fraction of the axes and is a
guide, these are data and participate in autoscaling. Each argument may
be a scalar or a sequence; scalars broadcast.
Source code in python/pyplotrs/axes.py
vlines
¶
vlines(
x,
ymin,
ymax,
*,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
linestyle: str = "solid",
label: str | None = None,
zorder: float = 0.0
) -> "Axes"
Vertical line segments at each x, spanning ymin to ymax in
data coordinates (see hlines).
Source code in python/pyplotrs/axes.py
axhline
¶
axhline(
y: float = 0.0,
*,
xmin: float = 0.0,
xmax: float = 1.0,
color=None,
linewidth: float | None = None,
linestyle: str = "solid"
) -> "Axes"
Draw a horizontal reference line at data y spanning the axes
fraction xmin..xmax (0 = left edge, 1 = right).
y is folded into the y limits so the guide cannot land outside the
frame; xmin/xmax are axes fractions, not data, so x is untouched.
Source code in python/pyplotrs/axes.py
axvline
¶
axvline(
x: float = 0.0,
*,
ymin: float = 0.0,
ymax: float = 1.0,
color=None,
linewidth: float | None = None,
linestyle: str = "solid"
) -> "Axes"
Draw a vertical reference line at data x spanning the axes
fraction ymin..ymax. x is folded into the x limits so the guide
stays inside the frame; ymin/ymax are fractions. See axhline.
Source code in python/pyplotrs/axes.py
axhspan
¶
axhspan(
ymin: float,
ymax: float,
*,
xmin: float = 0.0,
xmax: float = 1.0,
color=None,
alpha: float = 0.3
) -> "Axes"
Shade the horizontal band between data ymin and ymax (spanning
the axes fraction xmin..xmax in x). Drawn behind the data; the band
is folded into the y limits so it stays visible.
Source code in python/pyplotrs/axes.py
axvspan
¶
axvspan(
xmin: float,
xmax: float,
*,
ymin: float = 0.0,
ymax: float = 1.0,
color=None,
alpha: float = 0.3
) -> "Axes"
Shade the vertical band between data xmin and xmax (spanning
the axes fraction ymin..ymax in y). Drawn behind the data; the band
is folded into the x limits so it stays visible.
Source code in python/pyplotrs/axes.py
axline
¶
axline(
xy1,
*,
xy2=None,
slope: float | None = None,
color=None,
linewidth: float | None = None,
linestyle: str = "solid"
) -> "Axes"
Draw an infinite line through xy1, defined by a second point
xy2 or a slope. Clipped to the plot rect. Alone among the
guides it contributes nothing to the limits - it is infinite, so it has
no extent to contribute and is always on screen already.
Source code in python/pyplotrs/axes.py
rectangle
¶
rectangle(
xy,
width: float,
height: float,
*,
angle: float = 0.0,
facecolor=None,
edgecolor=None,
linewidth: float = 1.0,
linestyle: str = "solid",
alpha: float = 1.0,
fill: bool = True,
hatch: str | None = None
) -> "Axes"
Add an axis-aligned (or angle-rotated, degrees CCW) rectangle with
lower-left corner xy and the given data-space width/height.
Source code in python/pyplotrs/axes.py
circle
¶
circle(
xy,
radius: float,
*,
facecolor=None,
edgecolor=None,
linewidth: float = 1.0,
linestyle: str = "solid",
alpha: float = 1.0,
fill: bool = True,
hatch: str | None = None
) -> "Axes"
Add a circle of data-space radius centered at xy. Note it maps
to an ellipse when the x/y scales differ (use set(aspect='equal')).
Source code in python/pyplotrs/axes.py
ellipse
¶
ellipse(
xy,
width: float,
height: float,
*,
angle: float = 0.0,
facecolor=None,
edgecolor=None,
linewidth: float = 1.0,
linestyle: str = "solid",
alpha: float = 1.0,
fill: bool = True,
hatch: str | None = None
) -> "Axes"
Add an ellipse of full data-space width/height (diameters)
centered at xy, rotated angle degrees CCW.
Source code in python/pyplotrs/axes.py
polygon
¶
polygon(
points,
*,
closed: bool = True,
facecolor=None,
edgecolor=None,
linewidth: float = 1.0,
linestyle: str = "solid",
alpha: float = 1.0,
fill: bool = True,
hatch: str | None = None
) -> "Axes"
Add a polygon through the data-space vertices points.
Source code in python/pyplotrs/axes.py
fill
¶
fill(
x,
y,
*,
facecolor=None,
edgecolor=None,
linewidth: float = 1.0,
linestyle: str = "solid",
alpha: float = 1.0,
hatch: str | None = None
) -> "Axes"
Fill the closed polygon through (x, y) - matplotlib's ax.fill.
A thin wrapper over polygon taking parallel x/y arrays
instead of a list of point pairs; facecolor cycles the palette like
a data mark when omitted. It is a patch like polygon (drawn
over the data, outside the zorder/legend contract the marks share) -
call polygon directly for its other knobs.
Source code in python/pyplotrs/axes.py
arrow
¶
Draw an arrow from data (x, y) to (x + dx, y + dy).
Source code in python/pyplotrs/axes.py
text
¶
text(
x,
y,
s,
*,
color=None,
fontsize: float | None = None,
weight: str = "normal",
style: str = "normal",
ha: str = "left",
va: str = "baseline",
rotation: float = 0.0
) -> "Axes"
Draw s at data coordinates (x, y).
ha is left/center/right; va is
baseline/bottom/center/top. s may contain $...$
math. color defaults to the theme text color. weight is
normal or bold and style is normal or italic; both
select a real face of the body family, so the glyphs are genuinely bold
or italic rather than synthetically slanted.
rotation turns the text counter-clockwise by that many degrees
about its anchor, and it stays selectable text in PDF/SVG - the
rotation is a group transform in the IR, not baked-out paths.
Source code in python/pyplotrs/axes.py
annotate
¶
annotate(
text,
xy,
*,
xytext=None,
color=None,
fontsize: float | None = None,
weight: str = "normal",
style: str = "normal",
arrow: bool = True,
ha: str = "left",
va: str = "bottom",
rotation: float = 0.0
) -> "Axes"
Annotate the data point xy with text placed at xytext
(defaults to xy), optionally drawing a callout arrow from the text to
the point. All coordinates are in data space. weight/style select
a bold and/or italic face (see text).
Source code in python/pyplotrs/axes.py
legend
¶
legend(
*,
loc: str | None = None,
ncol: int = 1,
title: str | None = None,
frameon: bool = True,
fontsize: float | None = None
)
Enable an auto-legend over this axes' labeled marks.
loc is best / upper right / upper left / lower right
/ lower left / upper center / lower center; None uses
this axes class's default. best picks the corner that overlaps the
data least.
ncol lays the keys out in that many columns, filled down then
across - the usual fix for a legend tall enough to crowd the data.
title puts a heading above the keys, frameon=False drops the
box and its background, and fontsize overrides theme.legend_size
for this legend only.
Source code in python/pyplotrs/axes.py
axis
¶
Coarse axis control: "off"/"on" toggle the frame (spines,
ticks, grid); "equal" requests an equal data-unit aspect.
Source code in python/pyplotrs/axes.py
twinx
¶
A second axes sharing this one's x-axis but with an independent y-axis drawn on the right (e.g. two series in different units). Plot on the returned axes; it overlays the same cell.
Source code in python/pyplotrs/axes.py
twiny
¶
A second axes sharing this one's y-axis with an independent x-axis drawn along the top.
inset_axes
¶
A child axes occupying bounds = (x0, y0, width, height) given as
fractions of this axes' plot area ((0, 0) = lower-left). Returns the
inset axes to plot on.
Source code in python/pyplotrs/axes.py
secondary_xaxis
¶
A functional secondary x-axis at location ("top"/"bottom").
functions=(forward, inverse) maps primary→secondary data (e.g.
Celsius↔Fahrenheit); omit for a plain duplicate axis. Returns self.
Source code in python/pyplotrs/axes.py
secondary_yaxis
¶
A functional secondary y-axis at location ("left"/"right").
Source code in python/pyplotrs/axes.py
set
¶
set(
*,
title=None,
xlabel=None,
ylabel=None,
xlim=None,
ylim=None,
xscale=None,
yscale=None,
xticks=None,
yticks=None,
xticklabels=None,
yticklabels=None,
xformatter=None,
yformatter=None,
grid=None,
aspect=None,
xmargin=None,
ymargin=None,
margin=None,
xinverted=None,
yinverted=None,
xminor=None,
yminor=None,
minor=None,
tick_direction=None,
tick_length=None,
xtickrotation=None
) -> "Axes"
Set any combination of title, axis labels, view limits, axis scales, and tick/grid/aspect/margin controls.
xscale/yscale accept "linear" (default), "log",
"symlog", "logit" or a pyplotrs.scales.Scale.
xticks/yticks pin tick positions; xticklabels/yticklabels
give matching label strings. xformatter/yformatter accept a
pyplotrs.ticker.Formatter, a "{x:.2f}" template, or a
callable. grid overrides the theme grid; aspect="equal" equalizes
the data-unit scale on both axes.
Passing xlim="auto" (or ylim) clears a previously pinned limit
and returns that axis to autoscaling - None means "leave alone", so
it cannot double as a reset.
xmargin/ymargin (or margin for both) set the autoscale
padding as a fraction of the data span, replacing the 5% default;
0 gives limits tight to the data. xinverted/yinverted
make an axis descend without pinning numbers, which composes with
autoscaling. xminor/yminor (or minor) put that many minor
intervals inside each major one - non-linear scales already subdivide
themselves, so this is for linear axes. tick_direction is "out"
(default) or "in", and tick_length overrides the tick mark
length in points.
xtickrotation is an angle in degrees for the x tick labels, or
"auto" (the default) to rotate only when the labels would otherwise
collide, or 0 to force them flat and accept the overlap. Long
category names on a bar chart are the case this exists for: drawn flat
they overprint each other, and the axis stops saying which bar is
which.
Source code in python/pyplotrs/axes.py
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 | |
get_xlim
¶
Effective x limits: the explicit xlim if set, else autoscaled -
and unified across the row when the figure was built sharex=True.
get_ylim
¶
get_xlabel
¶
get_ylabel
¶
get_title
¶
This axes' title, or None. Lives on the base class because all
three axes kinds have one - the rest of the getters are per-kind.
get_xscale
¶
get_yscale
¶
get_aspect
¶
get_xticks
¶
get_yticks
¶
get_xticklabels
¶
get_yticklabels
¶
get_legend_handles_labels
¶
(handles, labels) for the labeled marks, in draw order.
A handle is the mark's own dict: pyplotrs has no Artist objects, and the mark is what the legend key gets drawn from.
Source code in python/pyplotrs/axes.py
PolarAxes¶
PolarAxes
¶
Bases: _AxesBase
A polar axes: plot(theta, r) and scatter(theta, r).
Angles are in radians, measured counter-clockwise from the positive
x-axis (East), matching matplotlib's default; change this with
set(theta_zero_location=...) / set(theta_direction=...). Create one
with subplots(projection="polar") or add_subplot(spec,
projection="polar").
Source code in python/pyplotrs/polar.py
plot
¶
plot(
theta,
r,
*,
label: str | None = None,
color=None,
linewidth: float | None = None,
alpha: float = 1.0,
linestyle: str = "solid",
marker: str | None = None,
markersize: float = 5.0,
zorder: float = 0.0
) -> "PolarAxes"
Line through polar points (theta, r) (theta in radians).
Source code in python/pyplotrs/polar.py
scatter
¶
scatter(
theta,
r,
*,
label: str | None = None,
color=None,
markersize: float | None = None,
alpha: float = 1.0,
marker: str = "o",
edgecolor=None,
size: float | None = None,
zorder: float = 0.0
) -> "PolarAxes"
Scatter polar points (theta, r) (theta in radians).
markersize is a diameter in points; size is the matplotlib-style
area in pt² (see Axes.scatter).
Source code in python/pyplotrs/polar.py
legend
¶
legend(
*,
loc: str | None = None,
ncol: int = 1,
title: str | None = None,
frameon: bool = True,
fontsize: float | None = None
)
Enable an auto-legend over this axes' labeled marks.
loc is best / upper right / upper left / lower right
/ lower left / upper center / lower center; None uses
this axes class's default. best picks the corner that overlaps the
data least.
ncol lays the keys out in that many columns, filled down then
across - the usual fix for a legend tall enough to crowd the data.
title puts a heading above the keys, frameon=False drops the
box and its background, and fontsize overrides theme.legend_size
for this legend only.
Source code in python/pyplotrs/axes.py
set
¶
set(
*,
title=None,
rmin=None,
rmax=None,
rticks=None,
thetagrids=None,
theta_zero_location=None,
theta_direction=None,
rlabel_position=None
) -> "PolarAxes"
Set polar options: title; radial limits rmin/rmax; explicit
rticks (radii) and thetagrids (spoke angles, degrees); the zero
location ("E"/"N"/"W"/"S" or radians); the theta_direction
(1 counter-clockwise or -1 clockwise); and rlabel_position (the
angle in degrees along which radial tick labels are placed).
Source code in python/pyplotrs/polar.py
get_rlim
¶
get_rticks
¶
get_thetagrids
¶
Axes3D¶
Axes3D
¶
Bases: _AxesBase
A 3D axes. Marks (scatter/plot/surface) are projected to 2D paths by an orthographic camera and depth-sorted, then drawn through the normal IR.
Source code in python/pyplotrs/axes3d.py
scatter
¶
scatter(
xs,
ys,
zs,
*,
label: str | None = None,
color=None,
markersize: float | None = None,
alpha: float = 1.0,
marker: str = "o",
edgecolor=None,
size: float | None = None
) -> "Axes3D"
Scatter 3D points at (xs, ys, zs).
markersize is a diameter in points; size is the matplotlib-style
area in pt² (see Axes.scatter).
Source code in python/pyplotrs/axes3d.py
plot
¶
plot(
xs,
ys,
zs,
*,
label: str | None = None,
color=None,
linewidth: float = 1.5,
alpha: float = 1.0,
linestyle: str = "solid",
depthsort: bool = True
) -> "Axes3D"
Draw a 3D polyline through (xs, ys, zs).
depthsort controls how the line takes part in the painter's-order
pass. With it on (the default) each segment is sorted separately,
so the line occludes itself and interleaves correctly with surfaces and
points it passes through - which is what makes a knotted or spiraling
curve read as 3D at all. That costs one stroked path per segment, and
on a long line the rasterizer notices.
With it off the whole polyline is one path at a single depth: much faster on dense lines, and what matplotlib's mplot3d always does, at the cost of a line that cannot pass behind anything - including itself.
Source code in python/pyplotrs/axes3d.py
surface
¶
Draw a colormapped surface over the grid (X, Y, Z).
Source code in python/pyplotrs/axes3d.py
bar3d
¶
bar3d(
x,
y,
z,
dx,
dy,
dz,
*,
color=None,
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Draw 3D bars (boxes): base corners (x, y, z) with sizes
(dx, dy, dz) (each a scalar or per-bar array).
Source code in python/pyplotrs/axes3d.py
plot_wireframe
¶
plot_wireframe(
X,
Y,
Z,
*,
color=None,
linewidth: float = 0.8,
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Draw the grid (X, Y, Z) as a wireframe (row + column lines).
Source code in python/pyplotrs/axes3d.py
contour3d
¶
contour3d(
X,
Y,
Z,
*,
levels=None,
cmap="viridis",
linewidth: float = 1.5,
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Draw contour lines of the grid (X, Y, Z) at their z-heights
(marching squares in Rust); each level colored from cmap.
Source code in python/pyplotrs/axes3d.py
plot_trisurf
¶
plot_trisurf(
x,
y,
z,
*,
triangles=None,
cmap="viridis",
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Surface over scattered points (x, y, z): Delaunay-triangulate the
(x, y) plane (unless triangles index-triples are given) and shade
each facet by mean z.
Source code in python/pyplotrs/axes3d.py
quiver3d
¶
quiver3d(
x,
y,
z,
u,
v,
w,
*,
length: float = 1.0,
color=None,
linewidth: float = 1.5,
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Draw 3D arrows (u, v, w) rooted at (x, y, z), scaled by
length.
Source code in python/pyplotrs/axes3d.py
voxels
¶
voxels(
filled,
*,
color=None,
edgecolor=None,
alpha: float = 1.0,
label: str | None = None
) -> "Axes3D"
Draw a 3D boolean occupancy grid filled[i][j][k] as unit cubes.
Source code in python/pyplotrs/axes3d.py
legend
¶
legend(
*,
loc: str | None = None,
ncol: int = 1,
title: str | None = None,
frameon: bool = True,
fontsize: float | None = None
)
Enable an auto-legend over this axes' labeled marks.
loc is best / upper right / upper left / lower right
/ lower left / upper center / lower center; None uses
this axes class's default. best picks the corner that overlaps the
data least.
ncol lays the keys out in that many columns, filled down then
across - the usual fix for a legend tall enough to crowd the data.
title puts a heading above the keys, frameon=False drops the
box and its background, and fontsize overrides theme.legend_size
for this legend only.
Source code in python/pyplotrs/axes.py
set
¶
set(
*,
title=None,
xlabel=None,
ylabel=None,
zlabel=None,
xlim=None,
ylim=None,
zlim=None,
elev=None,
azim=None
) -> "Axes3D"
Source code in python/pyplotrs/axes3d.py
get_xlim
¶
get_ylim
¶
get_zlim
¶
get_xlabel
¶
get_ylabel
¶
get_zlabel
¶
Fonts¶
These module-level helpers configure body-font resolution, and which family
$...$ math is drawn in.
set_font_family
¶
Set the preferred sans-serif family names for body text, tried in order.
pyplotrs' analog of matplotlib's rcParams["font.sans-serif"]. The
default is Arial, Helvetica, Liberation Sans: the host's Arial
is used if installed, else Helvetica, else the bundled Liberation Sans
(Arial-metric-compatible). Whichever is chosen is embedded into every
saved figure (PDF/SVG/PNG/HTML), so a saved file always looks identical
when viewed on another machine.
Accepts either a single iterable or positional names::
pyplotrs.set_font_family("Calibri", "Arial")
pyplotrs.set_font_family(["Calibri", "Arial"])
Call with no arguments to restore the default. Arial and Helvetica are proprietary and never shipped with pyplotrs; they are only used if already present on the machine.
Source code in python/pyplotrs/__init__.py
get_font_family
¶
The preferred sans-serif family names, in order. Defaults to
["Arial", "Helvetica", "Liberation Sans"].
resolved_font_name
¶
The family name body text actually resolves to on this host right now
(e.g. "Arial" if installed, otherwise "Liberation Sans").
resolved_font_variants
¶
What each body face resolves to here, as [(selector, font name), ...]
for body, body-bold, body-italic and body-bolditalic.
Font matching is approximate: a family with no italic face resolves to its regular one, so asking for italic can quietly give you upright text. This makes that visible - two selectors reporting the same name means the host has no distinct face for one of them::
pyplotrs.resolved_font_variants()
# [('body', 'ArialMT'), ('body-bold', 'Arial-BoldMT'), ...]
Source code in python/pyplotrs/__init__.py
set_mathtext_fontset
¶
Which family $...$ math is drawn in - pyplotrs' analog of
matplotlib's rcParams["mathtext.fontset"].
"sans" (the default) sets math in your own body family wherever it has
the glyphs - variables in its italic, Greek, digits and the common
operators - and leaves the bundled STIX Two Math only what a text face
cannot draw: big operators, radicals, stretchy fences, the blackboard /
script / Fraktur alphabets, and any symbol your family is missing. Math
then matches the labels around it, which is what matplotlib does by
default.
"stix" sets every atom in STIX Two Math, so a span is uniformly
serif. Pair it with a serif body family or the math will not match the text
beside it::
pyplotrs.set_mathtext_fontset("stix")
pyplotrs.set_font_family("STIX Two Text", "Times New Roman")
Source code in python/pyplotrs/__init__.py
get_mathtext_fontset
¶
The active math font set, "sans" or "stix" (see
set_mathtext_fontset). Defaults to "sans".
Number formatting¶
set_unicode_minus
¶
Whether negative numeric labels are signed with U+2212 MINUS SIGN.
pyplotrs' analog of matplotlib's rcParams["axes.unicode_minus"], and
on by default for the same reason: the minus is drawn on the math axis at
the width of a +, where the ASCII hyphen-minus is a short, low
word-joiner that leaves a tick column looking ragged.
Turn it off with set_unicode_minus(False) if labels must survive being
copied out of a saved SVG/PDF and parsed back as numbers, or if a font you
have set lacks the glyph::
pyplotrs.set_unicode_minus(False)
This governs labels pyplotrs formats from a number - axis and colorbar
ticks, and the numeric ticker formatters. Text you supply
yourself is never rewritten, and $...$ math always uses a real minus.
Source code in python/pyplotrs/__init__.py
get_unicode_minus
¶
Whether negative numeric labels use U+2212 (see
set_unicode_minus). Defaults to True.