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.

class anyplotlib.markers.MarkerGroup(marker_type, name, kwargs, push_fn)[source]#

Bases: object

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

Return type:

None

to_wire(group_id)[source]#

Return a dict in the JS wire format for this marker group.

Parameters:

group_id (str)

Return type:

dict

class anyplotlib.markers.MarkerTypeDict(marker_type, push_fn)[source]#

Bases: object

Dict-like container for all named groups of one marker type.

Any modification (__setitem__, __delitem__) automatically triggers the _push_fn callback so the plot re-renders.

Parameters:

marker_type (str)

keys()[source]#
values()[source]#
items()[source]#
pop(name, *args)[source]#
Parameters:

name (str)

to_wire_list()[source]#

Serialise all groups to a list of wire-format dicts.

Return type:

list

class anyplotlib.markers.MarkerRegistry(push_fn, allowed=None)[source]#

Bases: object

Top-level two-level marker registry for a plot.

Usage:

plot.markers["circles"]["group1"].set(offsets=new_offsets)

plot.markers is a MarkerRegistry. Indexing by type returns a MarkerTypeDict (auto-created on first access).

Parameters:

allowed (frozenset | None)

add(marker_type, name=None, **kwargs)[source]#

Add a marker group, returning the MarkerGroup.

Parameters:
  • marker_type (str) – Type string, e.g. 'circles'.

  • name (str | None) – Group name. Auto-generated ('circles_1' etc.) if None.

  • **kwargs – Matplotlib-style kwargs for the group.

Return type:

MarkerGroup

remove(marker_type, name)[source]#

Remove a named group (triggers a push).

Parameters:
  • marker_type (str)

  • name (str)

Return type:

None

clear()[source]#

Remove all markers of all types.

Return type:

None

to_wire_list()[source]#

Flatten the full registry to a list of wire-format dicts.

Return type:

list