anyplotlib.Plot2D#

class anyplotlib.Plot2D(data, x_axis=None, y_axis=None, units='px', cmap=None, vmin=None, vmax=None, origin='upper')[source]#

Bases: object

2-D image plot panel.

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

  • cmap (str | None)

  • vmin (float | None)

  • vmax (float | None)

  • origin (str)

to_state_dict()[source]#

Return a JSON-serialisable copy of the current state.

Return type:

dict

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 call set_data().

set_data(data, x_axis=None, y_axis=None, units=None)[source]#

Replace the image data.

The origin supplied at construction is automatically re-applied so the new data is displayed with the same orientation.

Parameters:
Return type:

None

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 True pixels. Call with mask=None to 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. Pass None to clear the overlay.

  • color (str, optional) – CSS hex colour for the overlay, e.g. "#ff4444". Default red. Must be in #RRGGBB format.

  • alpha (float, optional) – Opacity in [0, 1]. Default 0.4 (40 % opaque).

Return type:

None

set_colormap(name)[source]#
Parameters:

name (str)

Return type:

None

set_clim(vmin=None, vmax=None)[source]#
Return type:

None

set_scale_mode(mode)[source]#
Parameters:

mode (str)

Return type:

None

property colormap_name: str#
add_widget(kind, color='#00e5ff', **kwargs)[source]#
Parameters:
Return type:

Widget

get_widget(wid)[source]#

Return the Widget object by ID string or Widget instance.

Return type:

Widget

remove_widget(wid)[source]#

Remove a widget by ID string or Widget instance.

Return type:

None

list_widgets()[source]#
Return type:

list

clear_widgets()[source]#
Return type:

None

on_changed(fn)[source]#

Decorator: fires on every pan/zoom/drag frame on this panel.

Parameters:

fn (Callable)

Return type:

Callable

on_release(fn)[source]#

Decorator: fires once when pan/zoom/drag settles on this panel.

Parameters:

fn (Callable)

Return type:

Callable

on_click(fn)[source]#

Decorator: fires on click on this panel.

Parameters:

fn (Callable)

Return type:

Callable

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, and last_widget_id.

Note

Registered keys take priority over the built-in r (reset view) shortcut.

Return type:

Callable

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

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)[source]#

Add circle markers at (x, y) positions in data coordinates.

Return type:

MarkerGroup

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:

MarkerGroup

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:

MarkerGroup

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:

MarkerGroup

add_arrows(offsets, U, V, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Return type:

MarkerGroup

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:

MarkerGroup

add_lines(segments, name=None, *, edgecolors='#ff0000', linewidths=1.5, hover_edgecolors=None, labels=None, label=None)[source]#
Return type:

MarkerGroup

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:

MarkerGroup

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:

MarkerGroup

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:

MarkerGroup

add_texts(offsets, texts, name=None, *, color='#ff0000', fontsize=12, hover_edgecolors=None, labels=None, label=None)[source]#
Return type:

MarkerGroup

remove_marker(marker_type, name)[source]#

Remove a named marker collection by type and name.

Parameters:
  • marker_type (str) – Collection type, e.g. "points", "vlines".

  • name (str) – The name used when the collection was created.

Return type:

None

clear_markers()[source]#

Remove all marker collections from this panel.

Return type:

None

list_markers()[source]#

Return a summary list of all marker collections on this panel.

Returns:

Each dict has keys "type", "name", and "n" (number of markers in the collection).

Return type:

list of dict