anyplotlib.Plot3D#

class anyplotlib.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: _BasePlot

3-D plot panel.

Supports four geometry types:

  • 'surface' – triangulated surface, Z-coloured via colormap.

  • 'scatter' – point cloud; single colour or per-point colors.

  • 'line' – connected line through 3-D points.

  • 'voxels' – shaded translucent cubes at the given centres; voxels lying on a PlaneWidget slice render more opaque.

A single point can be emphasised with set_highlight() (e.g. the “current” orientation in an IPF explorer), and bounds= fixes the axes extents for origin-true geometry such as unit vectors on a sphere. Draggable PlaneWidget slice selectors are added with add_widget().

Created by Axes.plot_surface(), Axes.scatter3d(), and Axes.plot3d().

Not an anywidget. Holds state in _state dict; 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 (see PlaneWidget):

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

list_widgets()[source]#

Return a list of all active widget objects on this panel.

Return type:

list

set_voxel_alpha(alpha, slice_alpha=None)[source]#

Set voxel transparency (geom_type 'voxels').

Parameters:
  • alpha (float) – Base opacity (0–1) for voxels not on any plane widget.

  • slice_alpha (float, optional) – Opacity for voxels lying on a PlaneWidget slice. None keeps the current value (default 0.95).

Return type:

None

to_state_dict()[source]#
Return type:

dict

property gpu_active: bool#

True if 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 gpu policy and point count call for it. Always False on the Canvas2D fallback path (no navigator.gpu, no adapter, device lost, or gpu=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.

Parameters:
Return type:

None

set_zoom(zoom)[source]#
Parameters:

zoom (float)

Return type:

None

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).

Parameters:
Return type:

None

set_ylabel(label, fontsize=None)[source]#

Set the y-axis label (mini-TeX allowed; default size 11 px).

Parameters:
Return type:

None

set_zlabel(label, fontsize=None)[source]#

Set the z-axis label (mini-TeX allowed; default size 11 px).

Parameters:
Return type:

None

get_xlim()[source]#

Return the data x range as (xmin, xmax).

Return type:

tuple

get_ylim()[source]#

Return the data y range as (ymin, ymax).

Return type:

tuple

get_zlim()[source]#

Return the data z range as (zmin, zmax).

Return type:

tuple

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). None reverts to the single color for 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:
  • x (float) – Position in data coordinates.

  • y (float) – Position in data coordinates.

  • z (float) – Position in data coordinates.

  • color (str, optional) – CSS colour of the dot and ring. Default "#ff1744".

  • size (float, optional) – Dot radius in pixels. Default 7.

Return type:

None

See also

clear_highlight

Remove 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),) * 3 to 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_sphere

Remove the reference sphere.

clear_sphere()[source]#

Remove the reference sphere set by set_sphere().

Return type:

None