Interactive Widgets#
anyplotlib.widgets — interactive overlay widget classes.
Base Class
Base class for all overlay widgets. |
Concrete Widgets
Draggable rectangle overlay widget for 2-D plots. |
|
Draggable circle overlay widget for 2-D plots. |
|
Draggable annular (ring) overlay widget for 2-D plots. |
|
Draggable crosshair overlay widget for 2-D plots. |
|
Draggable polygon overlay widget for 2-D plots. |
|
Text label overlay widget for 2-D plots. |
|
Draggable vertical line overlay widget for 1-D plots. |
|
Draggable horizontal line overlay widget for bar charts. |
|
Draggable range selection widget. |
Full Reference
- class anyplotlib.widgets.Widget(wtype, push_fn, **kwargs)[source]
Bases:
_EventMixinBase class for all overlay widgets.
Provides attribute-based state access, callbacks for interaction events, and automatic synchronization with the JavaScript renderer.
- Parameters:
- callbacks
Event callback registry. Register handlers via
widget.add_event_handler(fn, "pointer_move")or as a decorator:@widget.add_event_handler("pointer_move").Common event types:
"pointer_move"— fires on every drag frame"pointer_up"— fires once when drag settles"pointer_down"— fires on click/press event
- Type:
- set(_push=True, **kwargs)[source]
Update properties and send targeted update to JavaScript.
- Parameters:
- Return type:
None
Notes
Updates are sent as targeted widget updates, not full panel re-renders. This is more efficient for frequent updates during dragging.
- get(key, default=None)[source]
Get a widget property by name.
- to_dict()[source]
Return a dict copy of the widget state.
- Returns:
All widget properties including id and type.
- Return type:
- property visible: bool
Trueif the widget is rendered;Falseif hidden.
- show()[source]
Show the widget. Does not fire
pointer_movecallbacks.- Return type:
None
- hide()[source]
Hide the widget without removing it or its callbacks.
Call
show()to make it visible again. Does not firepointer_movecallbacks.- Return type:
None
- property id: str
Return the widget’s unique identifier.
- class anyplotlib.widgets.RectangleWidget(push_fn, *, x, y, w, h, color='#00e5ff')[source]
Bases:
WidgetDraggable rectangle overlay widget for 2-D plots.
- Parameters:
push_fn (Callable) – Update callback.
x (float) – Top-left corner position in pixel/data coordinates.
y (float) – Top-left corner position in pixel/data coordinates.
w (float) – Width and height in pixel/data coordinates.
h (float) – Width and height in pixel/data coordinates.
color (str, optional) – CSS colour for the rectangle outline. Default
"#00e5ff".
- class anyplotlib.widgets.CircleWidget(push_fn, *, cx, cy, r, color='#00e5ff')[source]
Bases:
WidgetDraggable circle overlay widget for 2-D plots.
- class anyplotlib.widgets.AnnularWidget(push_fn, *, cx, cy, r_outer, r_inner, color='#00e5ff')[source]
Bases:
WidgetDraggable annular (ring) overlay widget for 2-D plots.
- Parameters:
push_fn (Callable) – Update callback.
cx (float) – Center position in pixel/data coordinates.
cy (float) – Center position in pixel/data coordinates.
r_outer (float) – Outer and inner radii in pixel/data coordinates. Inner radius must be less than outer radius.
r_inner (float) – Outer and inner radii in pixel/data coordinates. Inner radius must be less than outer radius.
color (str, optional) – CSS colour for the ring outline. Default
"#00e5ff".
- Raises:
ValueError – If r_inner >= r_outer.
- class anyplotlib.widgets.CrosshairWidget(push_fn, *, cx, cy, color='#00e5ff')[source]
Bases:
WidgetDraggable crosshair overlay widget for 2-D plots.
- class anyplotlib.widgets.PolygonWidget(push_fn, *, vertices, color='#00e5ff')[source]
Bases:
WidgetDraggable polygon overlay widget for 2-D plots.
- Parameters:
- Raises:
ValueError – If fewer than 3 vertices provided.
- class anyplotlib.widgets.LabelWidget(push_fn, *, x, y, text='Label', fontsize=14, color='#00e5ff')[source]
Bases:
WidgetText label overlay widget for 2-D plots.
- Parameters:
push_fn (Callable) – Update callback.
x (float) – Label position in pixel/data coordinates.
y (float) – Label position in pixel/data coordinates.
text (str, optional) – Label text. Default
"Label".fontsize (int, optional) – Font size in points. Default 14.
color (str, optional) – CSS colour for the text. Default
"#00e5ff".
- class anyplotlib.widgets.VLineWidget(push_fn, *, x, color='#00e5ff')[source]
Bases:
WidgetDraggable vertical line overlay widget for 1-D plots.
Allows interactive selection of a single x-axis value. The line can be dragged left/right to change the selected position.
- class anyplotlib.widgets.HLineWidget(push_fn, *, y, color='#00e5ff')[source]
Bases:
WidgetDraggable horizontal line overlay widget for bar charts.
Allows interactive selection of a single y-axis value. The line can be dragged up/down to change the selected value.
- class anyplotlib.widgets.RangeWidget(push_fn, *, x0, x1, color='#00e5ff', style='band', y=0.0)[source]
Bases:
WidgetDraggable range selection widget.
Two display styles are available:
style='band'(default)Two connected vertical lines with a translucent fill band. Either line can be dragged independently; the whole band can be dragged by clicking inside it.
style='fwhm'Two circular handles joined by a dashed horizontal line drawn at height y (the half-maximum level). Only the x-positions of the handles are draggable. Use this to show/edit a FWHM interval on a peak.
- Parameters:
push_fn (Callable) – Update callback.
x0 (float) – Initial left and right positions in data coordinates.
x1 (float) – Initial left and right positions in data coordinates.
color (str, optional) – CSS colour. Default
"#00e5ff".style ({'band', 'fwhm'}, optional) – Visual style. Default
"band".y (float, optional) – Y-position (data coordinates) for the connecting line when
style='fwhm'. Ignored forstyle='band'. Default0.0.