Markers#
markers.py#
Marker registry for Plot1D and Plot2D panels inside a Figure.
The public API mirrors matplotlib’s collection kwargs:
- plot.add_circles(offsets, name=”group1”,
facecolors=”#ff0000”, edgecolors=”#ffffff”, radius=5, labels=[…])
plot.markers[“circles”][“group1”].set(offsets=new_offsets, radius=3)
Design#
MarkerGroup– a single named collection of markers (one type).MarkerTypeDict– dict-like for one type; mutations propagate to the plot.MarkerRegistry– top-level two-level dict: registry[type][name].
All state is stored as plain Python dicts; no traitlets here. The _push
callback is supplied by the parent plot and is responsible for serialising
the full registry into the panel’s JSON trait on the Figure widget.
Wire-format translation#
The JS renderer uses the same internal field names as the standalone viewers
(color, fill_color, fill_alpha, sizes, etc.). MarkerGroup
stores matplotlib-style names and to_wire() translates before JSON
serialisation.
Classes
A named collection of markers of one type on one plot. |
|
Dict-like container for all named groups of one marker type. |
|
Top-level two-level marker registry for a plot. |
Full Reference
- class anyplotlib.markers.MarkerGroup(marker_type, name, kwargs, push_fn)[source]
Bases:
objectA named collection of markers of one type on one plot.
- Parameters:
marker_type (str) – One of the supported marker types (
'circles','lines', …).name (str) – User-facing name (key in the parent
MarkerTypeDict).kwargs (dict) – Initial matplotlib-style kwargs for this group.
push_fn (callable) – Zero-arg callback that serialises the full registry and pushes it to the parent figure trait.
- set(**kwargs)[source]
Update one or more properties and push the change to the plot.
- Parameters:
**kwargs (dict) – Properties to update (e.g., offsets, radius, facecolors). Matplotlib-style names are translated to wire format.
- Return type:
None
- to_wire(group_id)[source]
Return a dict in the JS wire format for this marker group.
- class anyplotlib.markers.MarkerTypeDict(marker_type, push_fn)[source]
Bases:
objectDict-like container for all named groups of one marker type.
Any modification (
__setitem__,__delitem__) automatically triggers the_push_fncallback so the plot re-renders.- Parameters:
marker_type (str) – Type of markers (e.g., ‘circles’, ‘arrows’, ‘lines’).
push_fn (callable) – Zero-arg callback to trigger re-render on mutations.
- keys()[source]
Return group names.
- values()[source]
Return MarkerGroup objects.
- items()[source]
Return (name, MarkerGroup) pairs.
- pop(name, *args)[source]
Remove and return a MarkerGroup by name.
- class anyplotlib.markers.MarkerRegistry(push_fn, allowed=None)[source]
Bases:
objectTop-level two-level marker registry for a plot.
Usage:
plot.markers["circles"]["group1"].set(offsets=new_offsets)
plot.markersis aMarkerRegistry. Indexing by type returns aMarkerTypeDict(auto-created on first access).- Parameters:
allowed (frozenset | None)
- add(marker_type, name=None, **kwargs)[source]
Add a marker group, returning the
MarkerGroup.- Parameters:
- Returns:
The created marker group. Call
.set()to update, or access properties as attributes.- Return type:
Examples
>>> group = registry.add("circles", name="my_circles", offsets=[[10, 20]], radius=5) >>> group.set(radius=8)
- remove(marker_type, name)[source]
Remove a named marker group and trigger re-render.
- clear()[source]
Remove all markers of all types and trigger re-render.
- Return type:
None