Figure Plots#
figure_plots.py#
Pure-Python plot objects returned by Axes.imshow() / Axes.plot().
These are NOT anywidget subclasses. They hold all state in plain dicts and push changes into the parent Figure’s per-panel traitlet via _push().
Public classes#
GridSpec – describes a grid layout (nrows x ncols, ratios). SubplotSpec – a slice of a GridSpec (row/col spans). Axes – a grid cell; .imshow() / .plot() return a plot object. Plot2D – 2-D image panel, full Viewer2D-compatible API. Plot1D – 1-D line panel, full Viewer1D-compatible API.
- class anyplotlib.figure_plots.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
- class anyplotlib.figure_plots.SubplotSpec(gs, row_start, row_stop, col_start, col_stop)[source]#
Bases:
objectDescribes which grid cells a subplot occupies.
- class anyplotlib.figure_plots.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)
- 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', point_size=4.0, x_label='x', y_label='y', z_label='z', azimuth=-60.0, elevation=30.0, zoom=1.0)[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.)
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.)
- 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, label='')[source]#
Attach a 1-D line to this axes cell.
- bar(values, x_labels=None, x_centers=None, color='#4fc3f7', colors=None, bar_width=0.7, orient='v', baseline=0.0, show_values=False, units='', y_units='')[source]#
Attach a bar chart to this axes cell.
- Parameters:
values (array-like, shape (N,)) – Bar heights (vertical) or widths (horizontal).
x_labels (list of str, optional) – Category labels for each bar. Shown on the categorical axis instead of numeric tick values.
x_centers (array-like, optional) – Numeric positions of bar centres. Defaults to
0, 1, … N-1.color (str, optional) – Single CSS colour applied to every bar. Default
"#4fc3f7".colors (list of str, optional) – Per-bar colour list; overrides color where provided.
bar_width (float, optional) – Bar width as a fraction of the slot width (0–1). Default
0.7.orient (
"v"|"h", optional) – Vertical (default) or horizontal orientation.baseline (float, optional) – Value at which bars are rooted. Default
0.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.
- Return type:
- class anyplotlib.figure_plots.Plot1D(data, x_axis=None, units='px', y_units='', color='#4fc3f7', linewidth=1.5, label='')[source]#
Bases:
object1-D line plot panel.
Holds state in
_statedict; every mutation pushes to Figure trait. Exposes the full Viewer1D-compatible API plus the new marker API.- on_key(key_or_fn=None)[source]#
Register a key-press handler for this panel.
Two call forms are supported:
@plot.on_key('q') # fires only when 'q' is pressed def handler(event): ... @plot.on_key # fires for every registered key def handler(event): ...
The event carries:
key,mouse_x,mouse_y,phys_x, andlast_widget_id.Note
Registered keys take priority over the built-in r (reset view) shortcut.
- Return type:
- disconnect(cid)[source]#
Remove the callback registered under integer cid.
- Parameters:
cid (int)
- 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)[source]#
- 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)[source]#
Add point markers at (x, y) positions in data coordinates.
- Return type:
- add_hlines(y_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Add static horizontal lines at the given y positions.
- Return type:
- add_vlines(x_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Add static vertical lines at the given x positions.
- Return type:
- add_arrows(offsets, U, V, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
- 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)[source]#
- Return type:
- add_lines(segments, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
- 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)[source]#
- 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)[source]#
- 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)[source]#
- Return type:
- add_texts(offsets, texts, name=None, *, color='#ff0000', fontsize=12, hover_edgecolors=None, labels=None, label=None)[source]#
- Return type:
- class anyplotlib.figure_plots.Plot2D(data, x_axis=None, y_axis=None, units='px')[source]#
Bases:
object2-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:
data (np.ndarray)
units (str)
- on_key(key_or_fn=None)[source]#
Register a key-press handler for this panel.
Two call forms are supported:
@plot.on_key('q') # fires only when 'q' is pressed def handler(event): ... @plot.on_key # fires for every registered key def handler(event): ...
The event carries:
key,mouse_x,mouse_y,phys_x, andlast_widget_id.Note
Registered keys take priority over the built-in r (reset view) shortcut.
- Return type:
- disconnect(cid)[source]#
Remove the callback registered under integer cid.
- Parameters:
cid (int)
- Return type:
None
- 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
- 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)[source]#
Add circle markers at (x, y) positions in data coordinates.
- 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)[source]#
Add point markers at (x, y) positions in data coordinates.
- Return type:
- add_hlines(y_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Add static horizontal lines at the given y positions.
- Return type:
- add_vlines(x_values, name=None, *, color='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Add static vertical lines at the given x positions.
- Return type:
- add_arrows(offsets, U, V, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
- 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)[source]#
- Return type:
- add_lines(segments, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
- 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)[source]#
- 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)[source]#
- 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)[source]#
- Return type:
- add_texts(offsets, texts, name=None, *, color='#ff0000', fontsize=12, hover_edgecolors=None, labels=None, label=None)[source]#
- Return type:
- class anyplotlib.figure_plots.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.figure_plots.Plot3D(geom_type, x, y, z, *, colormap='viridis', color='#4fc3f7', 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)[source]#
Bases:
object3-D plot panel.
Supports three geometry types matching matplotlib’s 3-D Axes API:
'surface'– triangulated surface, Z-coloured via colormap.'scatter'– point cloud, single colour.'line'– connected line through 3-D points.
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:
- on_key(key_or_fn=None)[source]#
Register a key-press handler for this panel.
Two call forms are supported:
@plot.on_key('q') # fires only when 'q' is pressed def handler(event): ... @plot.on_key # fires for every registered key def handler(event): ...
The event carries:
key,mouse_x,mouse_y, andlast_widget_id.Note
Registered keys take priority over the built-in r (reset view) shortcut.
- Return type:
- disconnect(cid)[source]#
Remove the callback registered under integer cid.
- Parameters:
cid (int)
- Return type:
None
- set_colormap(name)[source]#
Set the surface colormap (ignored for scatter/line).
- Parameters:
name (str)
- Return type:
None
- class anyplotlib.figure_plots.PlotBar(values, x_labels=None, x_centers=None, color='#4fc3f7', colors=None, bar_width=0.7, orient='v', baseline=0.0, show_values=False, units='', y_units='')[source]#
Bases:
objectBar-chart plot panel.
Not an anywidget. Holds state in
_statedict; every mutation calls_push()which writes to the parent Figure’s panel trait.Supports draggable
VLineWidgetandHLineWidgetoverlays viaadd_vline_widget()/add_hline_widget().Created by
Axes.bar().- Parameters:
- update(values, x_centers=None, x_labels=None)[source]#
Replace bar values; recalculates the value-axis range automatically.
- 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
- 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:
- on_click(fn)[source]#
Decorator: fires when the user clicks a bar.
The
Eventhasbar_index,value,x_center, andx_label.
- on_key(key_or_fn=None)[source]#
Register a key-press handler for this panel.
Two call forms are supported:
@plot.on_key('q') # fires only when 'q' is pressed def handler(event): ... @plot.on_key # fires for every registered key def handler(event): ...
The event carries:
key,mouse_x,mouse_y, andlast_widget_id.- Return type: