Axes, Plots & Layout#
Axes
A single grid cell in a Figure. |
|
|
A floating inset sub-plot that overlays the main Figure grid. |
Plot Classes
1-D line plot panel returned by |
|
2-D image plot panel. |
|
2-D mesh plot panel created by |
|
3-D plot panel. |
|
Bar-chart plot panel. |
Layout
Define a grid of subplot cells. |
|
Describes which grid cells a subplot occupies. |
Full Reference
- class anyplotlib.axes.Axes(fig, spec)[source]
Bases:
objectA single grid cell in a Figure.
Returned by Figure.add_subplot() and Figure.subplots(). Call .imshow() or .plot() to attach a data plot and get back a Plot2D or Plot1D object.
- Parameters:
fig (Figure)
spec (SubplotSpec)
- imshow(data, axes=None, units='px', cmap=None, vmin=None, vmax=None, origin='upper')[source]
Attach a 2-D image to this axes cell.
- Parameters:
data (np.ndarray, shape (H, W) or (H, W, 3|4)) – Image data. 2-D arrays are colormapped.
(H, W, 3)/(H, W, 4)arrays render as true-colour RGB(A): uint8 values are used directly; floats are interpreted as 0–1 (or 0–255 when the max exceeds 1).cmap/vmin/vmaxand the colorbar do not apply to RGB images.axes ([x_axis, y_axis], optional) – Physical coordinate arrays for each axis.
units (str, optional) – Axis units label. Default
"px".cmap (str, optional) – Colormap name (e.g.
"viridis","inferno"). Defaults to"gray".vmin (float, optional) – Colormap clipping limits in data units. Values outside this range are clamped to the colormap endpoints. Defaults to the data min / max.
vmax (float, optional) – Colormap clipping limits in data units. Values outside this range are clamped to the colormap endpoints. Defaults to the data min / max.
origin (
"upper"|"lower", optional) – Where row 0 of the array is placed."upper"(default) puts row 0 at the top, matching the usual image convention."lower"puts row 0 at the bottom, matching the matplotlib convention for matrices / scientific plots.
- Return type:
- pcolormesh(data, x_edges=None, y_edges=None, units='')[source]
Attach a 2-D mesh to this axes cell using edge coordinates.
Follows the matplotlib pcolormesh convention: x_edges and y_edges are the cell edge coordinates, so they have length N+1 and M+1 respectively for an (M, N) data array.
- plot_surface(X, Y, Z, *, colormap='viridis', x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0)[source]
Attach a 3-D surface to this axes cell.
- Parameters:
X (array-like) – 2-D grid arrays of the same shape (e.g. from
np.meshgrid), or 1-D centre arrays for X/Y with a 2-D Z.Y (array-like) – 2-D grid arrays of the same shape (e.g. from
np.meshgrid), or 1-D centre arrays for X/Y with a 2-D Z.Z (array-like) – 2-D grid arrays of the same shape (e.g. from
np.meshgrid), or 1-D centre arrays for X/Y with a 2-D Z.colormap (str, optional Matplotlib colormap name. Default
'viridis'.)x_label (str, optional Axis labels.)
y_label (str, optional Axis labels.)
z_label (str, optional Axis labels.)
azimuth (float, optional Initial camera angles in degrees.)
elevation (float, optional Initial camera angles in degrees.)
zoom (float, optional Initial zoom factor.)
- Return type:
- scatter3d(x, y, z, *, color='#4fc3f7', colors=None, point_size=4.0, x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0, bounds=None, gpu='auto')[source]
Attach a 3-D scatter plot to this axes cell.
- Parameters:
x (array-like, shape (N,) Point coordinates.)
y (array-like, shape (N,) Point coordinates.)
z (array-like, shape (N,) Point coordinates.)
color (str, optional CSS colour for all points.)
colors (list of "#rrggbb" or (N, 3) array, optional) – Per-point colours (overrides color). Floats are 0–1.
point_size (float, optional Radius of each point in pixels.)
x_label (str, optional Axis labels.)
y_label (str, optional Axis labels.)
z_label (str, optional Axis labels.)
azimuth (float, optional Initial camera angles in degrees.)
elevation (float, optional Initial camera angles in degrees.)
zoom (float, optional Initial zoom factor.)
bounds (((xmin, xmax), (ymin, ymax), (zmin, zmax)), optional) – Fix the axes bounds instead of fitting them to the data — keeps the origin and scale stable, e.g.
((-1, 1),) * 3for unit vectors on a sphere.gpu (
"auto"| bool, optional) – WebGPU acceleration policy."auto"(default) renders on the GPU when available and the cloud exceeds ~20k points, else Canvas2D;Truealways attempts GPU;Falseforces Canvas2D. Falls back silently when WebGPU is unavailable — checkPlot3D.gpu_activefor the actual path.
- Return type:
- voxels(x, y, z, *, colors=None, color='#4fc3f7', size=1.0, alpha=0.3, x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0, bounds=None, gpu='auto')[source]
Attach a 3-D voxel plot: shaded translucent cubes at the centres.
Designed for volumetric grain/label maps. Add draggable
PlaneWidgetslice selectors withplot.add_widget("plane", axis=..., position=...)— voxels lying on a plane render atvoxel_slice_alpha(more opaque) so the selected slice pops out of the translucent volume.Large volumes With WebGPU (
gpu="auto", the default, active above ~8k cubes when a GPU is present) hundreds of thousands of voxels render interactively via instancing. On the Canvas2D fallback the budget is ~20k cubes (~3–6 µs each); a warning is emitted above that only whengpu=False. For volumes too large even for the GPU (e.g. a 512 × 512 × 300 tomogram = 78M voxels), downsample with stride slicing (vol[::s, ::s, ::s]) or draw only grain-boundary voxels, and pair the 3-D overview with linked full-resolution 2-D slice panels — the voxel grain explorer example demonstrates this pattern.- Parameters:
x (array-like, shape (N,)) – Voxel centre coordinates.
y (array-like, shape (N,)) – Voxel centre coordinates.
z (array-like, shape (N,)) – Voxel centre coordinates.
colors (list of "#rrggbb" or (N, 3) array, optional) – Per-voxel colours (overrides color). Floats are 0–1.
color (str, optional Single CSS colour when colors is omitted.)
size (float, optional Cube edge length in data units. Default 1.)
alpha (float, optional) – Base voxel opacity (0–1). Default 0.3. See also
Plot3D.set_voxel_alpha().x_label (str, optional Axis labels.)
y_label (str, optional Axis labels.)
z_label (str, optional Axis labels.)
azimuth (float, optional Initial camera angles in degrees.)
elevation (float, optional Initial camera angles in degrees.)
zoom (float, optional Initial zoom factor.)
bounds (((xmin, xmax), (ymin, ymax), (zmin, zmax)), optional) – Fix the axes bounds instead of fitting them to the data.
gpu (
"auto"| bool, optional) – WebGPU acceleration policy."auto"(default) renders cubes on the GPU when available and the set exceeds ~8k;Truealways attempts GPU;Falseforces Canvas2D. Falls back silently when WebGPU is unavailable — seePlot3D.gpu_active.
- Return type:
- plot3d(x, y, z, *, color='#4fc3f7', linewidth=1.5, x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0)[source]
Attach a 3-D line plot to this axes cell.
- Parameters:
x (array-like, shape (N,) Point coordinates along the line.)
y (array-like, shape (N,) Point coordinates along the line.)
z (array-like, shape (N,) Point coordinates along the line.)
color (str, optional CSS colour.)
linewidth (float, optional Stroke width in pixels.)
x_label (str, optional Axis labels.)
y_label (str, optional Axis labels.)
z_label (str, optional Axis labels.)
azimuth (float, optional Initial camera angles in degrees.)
elevation (float, optional Initial camera angles in degrees.)
zoom (float, optional Initial zoom factor.)
- Return type:
- plot(data, axes=None, units='px', y_units='', color='#4fc3f7', linewidth=1.5, linestyle='solid', ls=None, alpha=1.0, marker='none', markersize=4.0, label='', yscale='linear')[source]
Attach a 1-D line to this axes cell.
- Parameters:
data (array-like, shape (N,)) – Y values. Must be 1-D.
axes (list, optional) –
[x_axis]— a one-element list containing the x-coordinates (shape(N,)). If omitted the x-axis defaults to0, 1, …, N-1.units (str, optional) – Label for the x-axis (e.g.
"eV","s"). Default"px".y_units (str, optional) – Label for the y-axis. Default
""(no label).color (str, optional) – CSS colour string for the line (hex,
rgb(), named colour, etc.). Default"#4fc3f7".linewidth (float, optional) – Stroke width in pixels. Default
1.5.linestyle (str, optional) – Dash pattern. Accepted values:
"solid"("-"),"dashed"("--"),"dotted"(":"),"dashdot"("-.") . Default"solid".ls (str, optional) – Short alias for linestyle. Takes precedence if both are given.
alpha (float, optional) – Line opacity in the range 0–1. Default
1.0(fully opaque).marker (str, optional) – Per-point marker symbol. Supported values:
"o"(circle),"s"(square),"^"(triangle-up),"v"(triangle-down),"D"(diamond),"+"(plus),"x"(cross),"none"(no markers). Default"none".markersize (float, optional) – Marker radius / half-side in pixels. Default
4.0.label (str, optional) – Legend label. A legend is only drawn when at least one line has a non-empty label. Default
""(no legend entry).yscale (str)
- Returns:
Live plot object. Call methods on it to update data, add overlays, register callbacks, etc.
- Return type:
Examples
Basic sine wave with a physical x-axis:
import numpy as np import anyplotlib as apl x = np.linspace(0, 4 * np.pi, 512) fig, ax = apl.subplots(1, 1, figsize=(620, 320)) v = ax.plot(np.sin(x), axes=[x], units="rad", color="#ff7043", linewidth=2, label="sin") v # display in a Jupyter cell
Dashed line with semi-transparent markers:
v = ax.plot(data, linestyle="dashed", alpha=0.7, marker="o", markersize=4)
Overlay a second curve with
Plot1D.add_line():v.add_line(np.cos(x), x_axis=x, color="#aed581", label="cos")
- semilogy(data, axes=None, **kwargs)[source]
Attach a 1-D line with a logarithmic y-axis.
- bar(x, height=None, width=0.8, bottom=0.0, *, align='center', color='#4fc3f7', colors=None, orient='v', log_scale=False, group_labels=None, group_colors=None, show_values=False, units='', y_units='', x_labels=None, x_centers=None, bar_width=None, baseline=None, values=None)[source]
Attach a bar chart to this axes cell.
Signature mirrors
matplotlib.pyplot.bar:ax.bar(x, height, width=0.8, bottom=0.0, ...)
- Parameters:
x (x_labels → strings passed via) – Bar positions. Strings become category labels with auto-numeric centres; numbers are used directly as bar centres.
height (values →) – Bar heights. Pass a 2-D array to draw G grouped bars per category. If omitted x is treated as the heights and positions are generated automatically (backward-compatible call form).
width (bar_width →) – Bar width as a fraction of the category slot (0–1). Default
0.8.bottom (baseline →) – Value at which bars are rooted (baseline). Default
0.align (
"center"|"edge", optional) – Alignment of the bar relative to its x position. Currently only"center"is rendered; stored for future use.color (str, optional) – Single CSS colour applied to every bar. Default
"#4fc3f7".colors (list of str, optional) – Per-bar colour list (ungrouped) or ignored when group_colors is set.
orient (
"v"|"h", optional) – Vertical (default) or horizontal orientation.log_scale (bool, optional) – Use a logarithmic value axis. Non-positive values are clamped to
1e-10for display. DefaultFalse.group_labels (list of str, optional) – Legend labels for each group in a grouped bar chart.
group_colors (list of str, optional) – CSS colours per group. Defaults to a built-in palette.
show_values (bool, optional) – Draw the numeric value above / beside each bar.
units (str, optional) – Label for the categorical axis.
y_units (str, optional) – Label for the value axis.
aliases (Backward-compatible keyword)
------------------------------------
height
x
width
bottom
x
- Return type:
- class anyplotlib.axes.InsetAxes(fig, w_frac, h_frac, *, corner='top-right', title='')[source]
Bases:
AxesA floating inset sub-plot that overlays the main Figure grid.
Created via
Figure.add_inset(). Supports the same plot-factory methods asAxes(imshow,plot,pcolormesh, etc.).The inset is positioned at a corner of the figure and can be minimized (title bar only), maximized (expanded to fill ~72% of the figure), or restored to its normal size.
- Parameters:
fig (Figure)
w_frac (float) – Width and height as fractions of the figure dimensions (0–1).
h_frac (float) – Width and height as fractions of the figure dimensions (0–1).
corner (str, optional) – One of
"top-right","top-left","bottom-right","bottom-left". Default"top-right".title (str, optional) – Text shown in the inset title bar. Default
"".
Examples
>>> fig, ax = apl.subplots(1, 1, figsize=(640, 480)) >>> ax.imshow(data) >>> inset = fig.add_inset(0.3, 0.25, corner="top-right", title="Zoom") >>> inset.imshow(data[64:128, 64:128])
- property inset_state: str
"normal","minimized", or"maximized".- Type:
Current state
- minimize()[source]
Collapse the inset to its title bar only (idempotent).
- Return type:
None
- maximize()[source]
Expand the inset to ~72 % of the figure, centred (idempotent).
- Return type:
None
- restore()[source]
Return the inset to its normal corner position (idempotent).
- Return type:
None
- class anyplotlib.plot1d.Plot1D(data, x_axis=None, units='px', y_units='', color='#4fc3f7', linewidth=1.5, linestyle='solid', alpha=1.0, marker='none', markersize=4.0, label='', yscale='linear')[source]
Bases:
_BasePlot,_PanelMixin,_MarkerMixin1-D line plot panel returned by
Axes.plot().All display state is stored in a plain
_statedict. Every mutation ends with_push(), which serialises the state to the parentFiguretrait so the JS renderer picks up the change immediately.Supported line properties#
Set at construction time via
Axes.plot()or updated afterwards with the corresponding setter:Parameter
Default
Description
color"#4fc3f7"CSS colour string for the primary line.
linewidth1.5Stroke width in pixels.
linestyle(ls)"solid"Dash pattern:
"solid","dashed","dotted","dashdot". Shorthands"-","--",":","-."also accepted.alpha1.0Line opacity (0 = transparent, 1 = fully opaque).
marker"none"Per-point symbol:
"o"(circle),"s"(square),"^"/"v"(triangles),"D"(diamond),"+"/"x"(stroke-only), or"none".markersize4.0Marker radius / half-side in pixels.
label""Legend label (empty string = no legend entry).
Public API summary#
- Data
update()— replace y-data (and optionally the x-axis / units) without recreating the panel.- Overlay lines
add_line()/remove_line()/clear_lines()— overlay additional curves on the same axes.- Shaded spans
add_span()/remove_span()/clear_spans()— highlight a region along the x- or y-axis.- View control
set_view()/reset_view()— programmatic pan/zoom (users can also pan/zoom interactively with the mouse; press R to reset).- Interactive widgets
add_vline_widget()/add_hline_widget()/add_range_widget()— draggable overlays that report their position back to Python via callbacks. Manage them withget_widget(),remove_widget(),list_widgets(), andclear_widgets().- Static marker collections
add_points()/add_circles()/add_vlines()/add_hlines()/add_arrows()/add_ellipses()/add_lines()/add_rectangles()/add_squares()/add_polygons()/add_texts()— fixed overlays positioned at explicit data coordinates. Access them viaplot.markers[type][name]and manage withremove_marker(),clear_markers(), andlist_markers().- Callbacks
on_changed()/on_release()/on_click()/on_key()— react to pan/zoom frames, mouse clicks, and key-presses. Remove a handler withdisconnect().
- property line: Line1D
Handle for the primary line, enabling per-line callbacks.
Returns a
Line1Dwithid=Noneso you can register hover / click handlers scoped to just the primary line:@plot.line.on_click def on_primary_click(event): print(f"primary line clicked at x={event.x:.3f}")
- property data: ndarray
The primary line’s y-data (read-only).
Returns a float64 copy with
writeable=False. To replace the data callset_data().
- set_data(data, x_axis=None, units=None, y_units=None)[source]
Replace the primary line’s y-data and optionally its x-axis / units.
The y-axis range (
data_min/data_max) is recomputed automatically. The viewport is not reset — callreset_view()explicitly if needed.- Parameters:
data (array-like, shape (N,)) – New y values. Must be 1-D.
x_axis (array-like, shape (N,), optional) – New x coordinates. If omitted and the length of data matches the current x-axis, the existing x-axis is reused; otherwise it is reset to
0, 1, …, N-1.units (str, optional) – New x-axis label. Unchanged if not supplied.
y_units (str, optional) – New y-axis label. Unchanged if not supplied.
- Return type:
None
- add_line(data, x_axis=None, color='#4fc3f7', linewidth=1.5, linestyle='solid', ls=None, alpha=1.0, marker='none', markersize=4.0, label='')[source]
Overlay an additional curve on this panel.
The y-axis range is automatically expanded to include the new data so all lines remain fully visible.
- Parameters:
data (array-like, shape (N,)) – Y values for the new line. Must be 1-D.
x_axis (array-like, shape (N,), optional) – X coordinates. Defaults to the primary line’s x-axis.
color (str, optional) – CSS colour string. Default
"#4fc3f7".linewidth (float, optional) – Stroke width in pixels. Default
1.5.linestyle (str, optional) – Dash pattern:
"solid","dashed","dotted","dashdot"(or shorthands). Default"solid".ls (str, optional) – Short alias for linestyle.
alpha (float, optional) – Line opacity (0–1). Default
1.0.marker (str, optional) – Per-point marker symbol (see
Plot1D). Default"none".markersize (float, optional) – Marker radius / half-side in pixels. Default
4.0.label (str, optional) – Legend label. Default
""(no legend entry).
- Returns:
A handle to the new overlay line. Use it to register per-line hover/click callbacks or to remove the line later:
line = v.add_line(fit, color="#ffcc00", label="fit") line.remove() # remove it @line.on_click # per-line click handler def clicked(event): ...
- Return type:
Line1D
- remove_line(lid)[source]
Remove an overlay line by its ID or
Line1Dhandle.The y-axis range is recomputed after removal.
- clear_lines()[source]
Remove all overlay lines, leaving the primary line intact.
The y-axis range is recomputed after clearing.
- Return type:
None
- add_span(v0, v1, axis='x', color=None)[source]
Add a shaded span along the x- or y-axis.
- Parameters:
v0 (float) – Start and end of the span in data coordinates.
v1 (float) – Start and end of the span in data coordinates.
axis (
"x"|"y", optional) – Which axis the span runs along. Default"x".color (str, optional) – CSS colour string (supports alpha, e.g.
"rgba(255,200,0,0.2)"). Defaults to a theme-appropriate yellow tint.
- Returns:
Span ID for use with
remove_span().- Return type:
- remove_span(sid)[source]
Remove a shaded span by its ID.
- clear_spans()[source]
Remove all shaded spans.
- Return type:
None
- add_vline_widget(x, color='#00e5ff')[source]
Add a draggable vertical-line overlay.
- Parameters:
- Returns:
Widget object. Register position callbacks with
on_changed()/on_release().- Return type:
- add_hline_widget(y, color='#00e5ff')[source]
Add a draggable horizontal-line overlay.
- Parameters:
- Returns:
Widget object. Register position callbacks with
on_changed()/on_release().- Return type:
- add_range_widget(x0, x1, color='#00e5ff', style='band', y=0.0, _push=True)[source]
Add a draggable range overlay to this panel.
- Parameters:
x0 (float) – Initial left and right edges in data coordinates.
x1 (float) – Initial left and right edges in data coordinates.
color (str, optional) – CSS colour string. Default
"#00e5ff".style ({'band', 'fwhm'}, optional) – Visual style.
'band'(default) draws two vertical lines with a translucent fill.'fwhm'draws two draggable circles connected by a dashed horizontal line at y (the half-maximum level), giving ano-------oFWHM indicator.y (float, optional) – Y-coordinate (data space) for the connecting line when
style='fwhm'. Ignored whenstyle='band'. Default 0._push (bool, optional) – Push state to JS immediately. Set to
Falsewhen adding several widgets at once; call_push()manually afterward.
- Returns:
Widget object. Register position callbacks with
on_changed()/on_release().- Return type:
- add_point_widget(x, y, color='#00e5ff', show_crosshair=True, _push=True)[source]
Add a freely-draggable control point to this panel.
- Parameters:
x (float) – Initial x position in data coordinates.
y (float) – Initial y position in data coordinates (value axis).
color (str, optional) – CSS colour string. Default
"#00e5ff".show_crosshair (bool, optional) – Draw dashed guide lines through the handle. Default
True. PassFalsefor a plain dot with no guide lines._push (bool, optional) – Push state to JS immediately. Set to
Falsewhen adding several widgets at once; call_push()manually afterward.
- Return type:
PointWidget
- set_view(x0=None, x1=None)[source]
Programmatically set the visible x range.
- reset_view()[source]
Reset the view to show the full x range of the primary line.
- Return type:
None
- set_color(color)[source]
Set the primary line colour.
- Parameters:
color (str) – Any CSS colour string (hex,
rgb(), named colour, etc.).- Return type:
None
- set_linewidth(linewidth)[source]
Set the primary line stroke width.
- Parameters:
linewidth (float) – Stroke width in pixels.
- Return type:
None
- set_linestyle(linestyle)[source]
Set the primary line dash pattern.
- Parameters:
linestyle (str) –
"solid"("-"),"dashed"("--"),"dotted"(":"), or"dashdot"("-.")- Return type:
None
- set_alpha(alpha)[source]
Set the primary line opacity.
- Parameters:
alpha (float) – Opacity in the range 0 (transparent) to 1 (fully opaque).
- Return type:
None
- set_marker(marker, markersize=None)[source]
Set the primary line per-point marker symbol.
- property color: str
- property x: ndarray
- property y: ndarray
- set_xlabel(label, fontsize=None)[source]
Set the x-axis label.
- set_ylabel(label, fontsize=None)[source]
Set the y-axis label. Same semantics as
set_xlabel().
- set_yscale(scale)[source]
Set the y-axis scale:
'linear'or'log'.- Parameters:
scale (str)
- Return type:
None
- add_circles(offsets, name=None, *, radius=5, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add circle markers at explicit (x, y) positions.
On 1-D panels circles are rendered as filled/stroked discs; radius is in canvas pixels (not data units).
- Parameters:
offsets (array-like, shape (N, 2)) – Marker positions as
[[x0, y0], [x1, y1], …]in data coordinates.name (str, optional) – Registry key. Auto-generated if omitted.
radius (float or array-like, optional) – Radius in pixels. Scalar or per-marker array. Default
5.facecolors (str or None, optional) – Fill colour.
None= no fill.edgecolors (str, optional) – Stroke colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Returns:
Live group object. Call
.set(**kwargs)to update in place.- Return type:
- add_points(offsets, name=None, *, sizes=5, color='#ff0000', facecolors=None, linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add point markers at (x, y) positions in data coordinates.
- Parameters:
offsets (array-like, shape (N, 2)) – Marker positions as
[[x0, y0], [x1, y1], …].name (str, optional) – Registry key. Auto-generated if omitted.
sizes (float or array-like, optional) – Radius in pixels. Scalar or per-marker array. Default
5.color (str, optional) – Stroke colour. Default
"#ff0000".facecolors (str or None, optional) – Fill colour.
None= no fill.linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_hlines(y_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add static horizontal lines spanning the full x range.
- Parameters:
y_values (array-like, shape (N,)) – Y positions of each line in data coordinates.
name (str, optional) – Registry key. Auto-generated if omitted.
color (str, optional) – Line colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.hover_edgecolors (str, optional) – Colour override applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_vlines(x_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add static vertical lines spanning the full y range.
- Parameters:
x_values (array-like, shape (N,)) – X positions of each line in data coordinates.
name (str, optional) – Registry key. Auto-generated if omitted.
color (str, optional) – Line colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.hover_edgecolors (str, optional) – Colour override applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_arrows(offsets, U, V, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add arrow markers at explicit (x, y) positions.
- Parameters:
offsets (array-like, shape (N, 2)) – Arrow tail positions as
[[x0, y0], …]in data coordinates.U (array-like, shape (N,)) – X and Y components of each arrow vector (in data units).
V (array-like, shape (N,)) – X and Y components of each arrow vector (in data units).
name (str, optional) – Registry key. Auto-generated if omitted.
edgecolors (str, optional) – Arrow colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.hover_edgecolors (str, optional) – Colour override applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_ellipses(offsets, widths, heights, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add ellipse markers at explicit (x, y) positions.
- Parameters:
offsets (array-like, shape (N, 2)) – Centre positions in data coordinates.
widths (float or array-like) – Full width and height of each ellipse in canvas pixels.
heights (float or array-like) – Full width and height of each ellipse in canvas pixels.
name (str, optional) – Registry key. Auto-generated if omitted.
angles (float or array-like, optional) – Rotation angle(s) in degrees. Default
0.facecolors (str or None, optional) – Fill colour.
None= no fill.edgecolors (str, optional) – Stroke colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_lines(segments, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add line-segment markers (static, not draggable).
- Parameters:
segments (array-like, shape (N, 2, 2)) – Each segment is
[[x0, y0], [x1, y1]]in data coordinates.name (str, optional) – Registry key. Auto-generated if omitted.
edgecolors (str, optional) – Line colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.hover_edgecolors (str, optional) – Colour override applied on mouse-hover.
labels (list of str, optional) – Per-segment tooltip labels.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_rectangles(offsets, widths, heights, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add rectangle markers at explicit (x, y) positions.
- Parameters:
offsets (array-like, shape (N, 2)) – Centre positions in data coordinates.
widths (float or array-like) – Full width and height of each rectangle in canvas pixels.
heights (float or array-like) – Full width and height of each rectangle in canvas pixels.
name (str, optional) – Registry key. Auto-generated if omitted.
angles (float or array-like, optional) – Rotation angle(s) in degrees. Default
0.facecolors (str or None, optional) – Fill colour.
None= no fill.edgecolors (str, optional) – Stroke colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_squares(offsets, widths, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add square markers at explicit (x, y) positions.
- Parameters:
offsets (array-like, shape (N, 2)) – Centre positions in data coordinates.
widths (float or array-like) – Side length of each square in canvas pixels.
name (str, optional) – Registry key. Auto-generated if omitted.
angles (float or array-like, optional) – Rotation angle(s) in degrees. Default
0.facecolors (str or None, optional) – Fill colour.
None= no fill.edgecolors (str, optional) – Stroke colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_polygons(vertices_list, name=None, *, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add polygon markers defined by explicit vertex lists.
- Parameters:
vertices_list (list of array-like, each shape (K, 2)) – One polygon per element; each is a list of
[x, y]vertices in data coordinates.name (str, optional) – Registry key. Auto-generated if omitted.
facecolors (str or None, optional) – Fill colour.
None= no fill.edgecolors (str, optional) – Stroke colour. Default
"#ff0000".linewidths (float, optional) – Stroke width in pixels. Default
1.5.alpha (float, optional) – Fill opacity (0–1). Default
0.3.hover_edgecolors (str, optional) – Colour overrides applied on mouse-hover.
hover_facecolors (str, optional) – Colour overrides applied on mouse-hover.
labels (list of str, optional) – Per-polygon tooltip labels.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- add_texts(offsets, texts, name=None, *, color='#ff0000', fontsize=12, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add text annotations at explicit (x, y) positions.
- Parameters:
offsets (array-like, shape (N, 2)) – Anchor positions in data coordinates.
name (str, optional) – Registry key. Auto-generated if omitted.
color (str, optional) – Text colour. Default
"#ff0000".fontsize (int, optional) – Font size in pixels. Default
12.hover_edgecolors (str, optional) – Colour override applied on mouse-hover.
labels (list of str, optional) – Per-annotation tooltip labels.
label (str, optional) – Collection-level tooltip label.
transform (str)
- Return type:
- class anyplotlib.plot2d.Plot2D(data, x_axis=None, y_axis=None, units='px', cmap=None, vmin=None, vmax=None, origin='upper')[source]
Bases:
_BasePlot,_PanelMixin,_MarkerMixin2-D image plot panel.
Not an anywidget. Holds state in
_statedict; every mutation calls_push()which writes to the parent Figure’s panel trait.- The marker API follows matplotlib conventions:
plot.add_circles(offsets, name=”g1”, facecolors=”#f00”, radius=5) plot.markers[“circles”][“g1”].set(radius=8)
- Parameters:
- property data: ndarray
The image data in the original user coordinate system (read-only).
Returns a float64 copy with
writeable=False. To replace the data callset_data().
- set_data(data, x_axis=None, y_axis=None, units=None)[source]
Replace the image data.
The
originsupplied at construction is automatically re-applied so the new data is displayed with the same orientation.
- set_overlay_mask(mask, color='#ff4444', alpha=0.4)[source]
Set (or clear) a transparent boolean mask drawn over the image.
The mask is composited client-side in the browser at alpha opacity using color for all
Truepixels. Call withmask=Noneto remove any existing overlay.- Parameters:
mask (ndarray of shape (H, W), bool or uint8, or None) – Boolean array aligned to the image data.
True/ non-zero pixels are filled with color at transparency alpha. PassNoneto clear the overlay.color (str, optional) – CSS hex colour for the overlay, e.g.
"#ff4444". Default red. Must be in#RRGGBBformat.alpha (float, optional) – Opacity in [0, 1]. Default 0.4 (40 % opaque).
- Return type:
None
- set_clim(vmin=None, vmax=None)[source]
- Return type:
None
- property colormap_name: str
- set_xlabel(label, fontsize=None)[source]
Set the x-axis label.
- set_ylabel(label, fontsize=None)[source]
Set the y-axis label. Same semantics as
set_xlabel().
- set_extent(x_axis, y_axis)[source]
- Return type:
None
- set_colorbar_label(label, fontsize=None)[source]
Set the colorbar label (mini-TeX allowed; default size 10 px).
- set_aspect(ratio)[source]
- Return type:
None
- add_widget(kind, color='#00e5ff', **kwargs)[source]
Add an overlay widget by kind name.
Dispatches to the dedicated
add_<kind>_widgetmethod. Supported kinds:"circle","rectangle","annular","polygon","crosshair","label".
- add_circle_widget(cx=None, cy=None, r=None, color='#00e5ff')[source]
Add a draggable circle overlay.
- Parameters:
- Return type:
- add_rectangle_widget(x=None, y=None, w=None, h=None, color='#00e5ff')[source]
Add a draggable rectangle overlay.
- add_annular_widget(cx=None, cy=None, r_outer=None, r_inner=None, color='#00e5ff')[source]
Add a draggable annular (ring) overlay.
- add_polygon_widget(vertices=None, color='#00e5ff')[source]
Add a draggable polygon overlay.
- Parameters:
color (str)
- Return type:
- add_crosshair_widget(cx=None, cy=None, color='#00e5ff')[source]
Add a draggable crosshair overlay.
- Parameters:
- Return type:
- add_label_widget(x=None, y=None, text='Label', fontsize=14, color='#00e5ff')[source]
Add a draggable text label overlay.
- set_view(x0=None, x1=None, y0=None, y1=None)[source]
Set the viewport to a data-space rectangle.
- Parameters:
x0 (float, optional) – Horizontal data-space range to show. If omitted the full x-extent is used for zoom calculation.
x1 (float, optional) – Horizontal data-space range to show. If omitted the full x-extent is used for zoom calculation.
y0 (float, optional) – Vertical data-space range to show. If omitted the full y-extent is used for zoom calculation.
y1 (float, optional) – Vertical data-space range to show. If omitted the full y-extent is used for zoom calculation.
center_x (Translates the requested rectangle into the zoom /)
renderer. (/ center_y state values used by the 2-D JS)
- Return type:
None
- reset_view()[source]
Reset pan and zoom to show the full image.
- Return type:
None
- add_circles(offsets, name=None, *, radius=5, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add circle markers at (x, y) positions in data coordinates.
- Parameters:
transform (str)
- Return type:
- add_points(offsets, name=None, *, sizes=5, color='#ff0000', facecolors=None, linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
Add point markers at (x, y) positions in data coordinates.
- Parameters:
transform (str)
- Return type:
- add_hlines(y_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add static horizontal lines at the given y positions.
- Parameters:
transform (str)
- Return type:
- add_vlines(x_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
Add static vertical lines at the given x positions.
- Parameters:
transform (str)
- Return type:
- add_arrows(offsets, U, V, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- add_ellipses(offsets, widths, heights, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- add_lines(segments, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- add_rectangles(offsets, widths, heights, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- add_squares(offsets, widths, name=None, *, angles=0, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- add_polygons(vertices_list, name=None, *, facecolors=None, edgecolors='#ff0000', linewidths=1.5, alpha=0.3, hover_edgecolors=None, hover_facecolors=None, labels=None, label=None, transform='data')[source]
- Parameters:
transform (str)
- Return type:
- class anyplotlib.plot2d.PlotMesh(data, x_edges=None, y_edges=None, units='')[source]
Bases:
Plot2D2-D mesh plot panel created by
Axes.pcolormesh().Accepts cell edge arrays (length N+1 / M+1) rather than centre arrays, matches matplotlib’s
pcolormeshconvention. Only'circles'and'lines'markers are supported.- Parameters:
data (np.ndarray)
units (str)
- class anyplotlib.plot3d.Plot3D(geom_type, x, y, z, *, colormap='viridis', color='#4fc3f7', colors=None, point_size=4.0, linewidth=1.5, x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0, bounds=None, voxel_size=1.0, alpha=None, gpu='auto')[source]
Bases:
_BasePlot3-D plot panel.
Supports four geometry types:
'surface'– triangulated surface, Z-coloured via colormap.'scatter'– point cloud; single colour or per-pointcolors.'line'– connected line through 3-D points.'voxels'– shaded translucent cubes at the given centres; voxels lying on aPlaneWidgetslice render more opaque.
A single point can be emphasised with
set_highlight()(e.g. the “current” orientation in an IPF explorer), andbounds=fixes the axes extents for origin-true geometry such as unit vectors on a sphere. DraggablePlaneWidgetslice selectors are added withadd_widget().Created by
Axes.plot_surface(),Axes.scatter3d(), andAxes.plot3d().Not an anywidget. Holds state in
_statedict; every mutation calls_push()which writes to the parent Figure’s panel trait.- Parameters:
- add_widget(kind, **kwargs)[source]
Add an interactive overlay widget to this 3-D panel.
Currently supports
"plane"— a draggable axis-aligned slice plane (seePlaneWidget):pw = vol.add_widget("plane", axis="z", position=24) @pw.add_event_handler("pointer_move") def on_drag(event): resliced(int(round(pw.position)))
- Parameters:
kind (str)
- remove_widget(wid)[source]
Remove a widget by ID string or Widget instance.
- Return type:
None
- set_voxel_alpha(alpha, slice_alpha=None)[source]
Set voxel transparency (geom_type
'voxels').
- property gpu_active: bool
Trueif this panel is currently rendering geometry on the GPU.Reflects the JS renderer’s decision after the first frame: WebGPU is used only when available and when the panel’s
gpupolicy and point count call for it. AlwaysFalseon the Canvas2D fallback path (nonavigator.gpu, no adapter, device lost, orgpu=False).
- set_colormap(name)[source]
Set the surface colormap (ignored for scatter/line).
- Parameters:
name (str)
- Return type:
None
- set_view(azimuth=None, elevation=None)[source]
Set the camera azimuth (°) and/or elevation (°).
Uses a targeted field push so re-aiming the camera never re-transmits the panel’s geometry — important for large voxel/scatter panels.
- reset_view()[source]
Restore the camera to the angles/zoom set at construction time.
- Return type:
None
- set_xlabel(label, fontsize=None)[source]
Set the x-axis label (mini-TeX allowed; default size 11 px).
- set_ylabel(label, fontsize=None)[source]
Set the y-axis label (mini-TeX allowed; default size 11 px).
- set_zlabel(label, fontsize=None)[source]
Set the z-axis label (mini-TeX allowed; default size 11 px).
- set_data(x, y, z)[source]
Replace the geometry data (same shape rules as the constructor).
Bounds given at construction time (
bounds=) are preserved.- Return type:
None
- set_point_colors(colors)[source]
Set (or clear) per-point colours on a scatter or voxels panel.
- Parameters:
colors (list of "#rrggbb" strings, (N, 3) array, or None) – One colour per point / voxel. Floats are interpreted as 0–1 (or 0–255 when the max exceeds 1).
Nonereverts to the singlecolorfor all elements.- Return type:
None
- set_highlight(x, y, z, *, color='#ff1744', size=7.0)[source]
Mark one 3-D point with an emphasised dot drawn on top.
The highlight is independent of the panel’s geometry — use it to flag the “current” item in a point cloud or on a surface (e.g. the orientation under a crosshair in an IPF explorer). Points on the far side of the data are drawn semi-transparent as a depth cue.
- Parameters:
- Return type:
None
See also
clear_highlightRemove the highlight.
- clear_highlight()[source]
Remove the highlight point set by
set_highlight().- Return type:
None
- set_sphere(radius=1.0, *, color='#9e9e9e', alpha=0.15, wireframe=True)[source]
Draw an origin-centred reference sphere behind the data.
Rendered as a shaded silhouette disk plus latitude/longitude wireframe arcs (far-side arcs dimmed). Scatter points on the far side of the sphere are also dimmed, so a point cloud on the sphere reads with correct depth — ideal for inverse-pole-figure / orientation plots of unit vectors.
Assumes origin-centred, isotropic bounds — pass
bounds=((-r, r),) * 3to the constructor so the sphere’s screen silhouette is a true circle.- Parameters:
radius (float, optional) – Sphere radius in data units. Default 1 (unit sphere).
color (str, optional) – Base CSS colour of the shading and wireframe. Default grey.
alpha (float, optional) – Opacity of the shaded silhouette (0–1). Default 0.15.
wireframe (bool, optional) – Draw latitude/longitude arcs. Default True.
- Return type:
None
See also
clear_sphereRemove the reference sphere.
- clear_sphere()[source]
Remove the reference sphere set by
set_sphere().- Return type:
None
- class anyplotlib.plot1d.PlotBar(x, height=None, width=0.8, bottom=0.0, *, align='center', color='#4fc3f7', colors=None, orient='v', log_scale=False, group_labels=None, group_colors=None, show_values=False, units='', y_units='', x_labels=None, x_centers=None, bar_width=None, baseline=None, values=None)[source]
Bases:
_BasePlot,_PanelMixinBar-chart plot panel.
Not an anywidget. Holds state in
_statedict; every mutation calls_push()which writes to the parent Figure’s panel trait.Supports grouped bars (pass a 2-D height array with shape
(N, G)), log-scale value axis, draggable overlay widgets, and hover/click callbacks.Created by
Axes.bar().- Parameters:
- set_data(height, x=None, x_labels=None, *, x_centers=None)[source]
Replace bar heights; recalculates the value-axis range automatically.
- Parameters:
height (array-like, shape
(N,)or(N, G)) – New bar heights. For grouped charts the group count G must match the original.x (array-like of numeric, optional) – New bar positions (replaces the stored
x_centers). Also accepts the legacy keyword aliasx_centers.
- Return type:
None
- set_color(color)[source]
Set a single colour for all bars.
- Parameters:
color (str)
- Return type:
None
- set_colors(colors)[source]
Set per-bar colours (list of CSS colour strings, length N).
- Return type:
None
- set_show_values(show)[source]
Show or hide in-bar value annotations.
- Parameters:
show (bool)
- Return type:
None
- set_log_scale(log_scale)[source]
Enable or disable a logarithmic value axis.
When log_scale is
Trueany non-positive values are clamped to1e-10for display; the data-range bounds are recalculated in log-space automatically.- Parameters:
log_scale (bool)
- Return type:
None
- set_xlabel(label, fontsize=None)[source]
Set the x-axis label (mini-TeX allowed; default size 10 px).
- set_ylabel(label, fontsize=None)[source]
Set the y-axis / value-axis label (mini-TeX allowed; default size 10 px).
- set_align(align)[source]
Set bar alignment:
'center'or'edge'.- Parameters:
align (str)
- Return type:
None
- set_orient(orient)[source]
Set bar orientation:
'v'(vertical) or'h'(horizontal).- Parameters:
orient (str)
- Return type:
None
- set_group_labels(labels)[source]
Replace the category labels on the category axis.
- Return type:
None
- set_xlim(xmin, xmax)[source]
Pan/zoom the x-axis to [xmin, xmax] in data coordinates.
- set_ylim(y_min, y_max)[source]
Fix the value-axis range to [y_min, y_max].
- reset_view()[source]
Reset pan/zoom to show all bars.
- Return type:
None
- add_vline_widget(x, color='#00e5ff')[source]
Add a draggable vertical line at data position x.
- Parameters:
- Return type:
- add_hline_widget(y, color='#00e5ff')[source]
Add a draggable horizontal line at value-axis position y.
- Parameters:
- Return type:
- add_range_widget(x0, x1, color='#00e5ff', style='band', y=0.0, _push=True)[source]
Add a draggable range overlay. See
Plot1D.add_range_widget()for full docs.
- class anyplotlib.figure.GridSpec(nrows, ncols, *, width_ratios=None, height_ratios=None)[source]
Bases:
objectDefine a grid of subplot cells.
- Parameters:
Examples
>>> gs = GridSpec(2, 3, width_ratios=[2, 1, 1]) >>> spec = gs[0, :] # top row spanning all columns >>> spec = gs[1, 1:3] # bottom-right 2 columns