anyplotlib.Widget#
- class anyplotlib.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, _notify=True, *, notify=None, **kwargs)[source]#
Update properties and send targeted update to JavaScript.
- Parameters:
notify (bool, optional) –
Whether to fire
pointer_movecallbacks. DefaultTrue.A
set()from Python is otherwise indistinguishable from a user drag: handlers that react to the widget moving will run, and one that writes back to the widget feeds into itself. Passnotify=Falsewhen you are the one moving the widget and the handlers are only meant to hear about user input:widget.set(x=new_x, notify=False)
This supersedes wrapping the call in
pause_events(), which suppresses every event type for the duration rather than just this update’s echo._notify (bool, optional) – Older spelling of
notify, kept as an alias.notifywins when both are given._push (bool, optional) – Whether to push update to renderer. Default True. Set to False internally to avoid echo loops.
**kwargs (dict) – Properties to update (e.g., x=100, y=50, radius=20). Geometry is read in the widget’s
coordsframe, so a widget created withcoords="data"takes calibrated values here.
- Return type:
None
Notes
No widget has a property called
notify, so the keyword cannot collide with one;_notify/_pushkeep their leading underscore for the same reason.Updates are sent as targeted widget updates, not full panel re-renders. This is more efficient for frequent updates during dragging.
- property coords: str#
"pixel"or"data".On a 2-D image panel,
"pixel"(the default) means image pixels — integer i is the centre of pixel i, row 0 at the top — and"data"means the calibrated values of the panel’s axes. Attribute reads (widget.cx),get(),to_dict()andset()all use this frame; drag callbacks therefore see calibrated values on a"data"widget. Choose it withcoords=on the plot’sadd_*_widgetmethod, or change it withset_coords().On 1-D and bar panels positions are always in data units, so this is
"data".Notes
The renderer always works in pixels, so a widget stores pixels and a
"data"widget converts on every read and write. Re-calibrating the panel (set_extent()) therefore keeps the widget on the same pixels; its data-coordinate values change. This differs fromcoords="data"marker groups, which store data values and so keep their data position (and move on screen).- Type:
Coordinate frame of this widget’s geometry
- set_coords(coords)[source]#
Switch the frame used for reading and writing geometry.
Does not move the widget.
- Parameters:
coords (
"pixel"|"data")- 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
- remove()[source]#
Remove this widget from the plot that owns it.
Equivalent to
plot.remove_widget(widget), but callable when you only hold the widget — handle-based APIs otherwise have to re-derive the owning plot to delete something they already have.Removing a widget that is not attached to a plot, or removing twice, is a no-op.
- Return type:
None
- property kind: str#
The widget kind, e.g.
"rectangle","crosshair","vline".The same string
add_widget()dispatches on (andwidget.get("type")returns), so code holding only a widget can branch on what it is withoutisinstancechecks.