anyplotlib.Plot2D#

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

Bases: _BasePlot, _PanelMixin, _MarkerMixin

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#
set_xlabel(label, fontsize=None)[source]#

Set the x-axis label.

Parameters:
  • label (str) – Label text. Supports the mini-TeX subset for scientific notation, e.g. r"$q$ ($\AA^{-1}$)" or r"$10^{-3}$ m" — see _BasePlot notes.

  • fontsize (float, optional) – Font size in CSS pixels. Default 11. None keeps the current size.

Return type:

None

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

Set the y-axis label. Same semantics as set_xlabel().

Parameters:
Return type:

None

set_xlim(xmin, xmax)[source]#
Parameters:
Return type:

None

set_ylim(ymin, ymax)[source]#
Parameters:
Return type:

None

get_xlim()[source]#
Return type:

tuple

get_ylim()[source]#
Return type:

tuple

get_xbound()[source]#
Return type:

tuple

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

Parameters:
Return type:

None

set_colorbar_visible(visible)[source]#
Parameters:

visible (bool)

Return type:

None

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>_widget method. Supported kinds: "circle", "rectangle", "annular", "polygon", "crosshair", "label".

Parameters:
Return type:

Widget

add_circle_widget(cx=None, cy=None, r=None, color='#00e5ff')[source]#

Add a draggable circle overlay.

Parameters:
Return type:

CircleWidget

add_rectangle_widget(x=None, y=None, w=None, h=None, color='#00e5ff')[source]#

Add a draggable rectangle overlay.

Parameters:
Return type:

RectangleWidget

add_annular_widget(cx=None, cy=None, r_outer=None, r_inner=None, color='#00e5ff')[source]#

Add a draggable annular (ring) overlay.

Parameters:
Return type:

AnnularWidget

add_polygon_widget(vertices=None, color='#00e5ff')[source]#

Add a draggable polygon overlay.

Parameters:

color (str)

Return type:

PolygonWidget

add_crosshair_widget(cx=None, cy=None, color='#00e5ff')[source]#

Add a draggable crosshair overlay.

Parameters:
Return type:

CrosshairWidget

add_label_widget(x=None, y=None, text='Label', fontsize=14, color='#00e5ff')[source]#

Add a draggable text label overlay.

Parameters:
Return type:

LabelWidget

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:

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, transform='data')[source]#

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

Parameters:

transform (str)

Return type:

MarkerGroup

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:

MarkerGroup

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:

MarkerGroup

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:

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, transform='data')[source]#
Parameters:

transform (str)

Return type:

MarkerGroup

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:

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, transform='data')[source]#
Parameters:

transform (str)

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, transform='data')[source]#
Parameters:

transform (str)

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, transform='data')[source]#
Parameters:

transform (str)

Return type:

MarkerGroup

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

transform (str)

Return type:

MarkerGroup