Logic for determining what color/width to draw instance nodes/edges.

The color can be determined by the current color palette as well as settings on the ColorManager object:

  • distinctly_color: “instances”, “nodes”, or “edges”

  • color_predicted: whether to use colors for predicted instances, or just plot them in yellow/grey

Initial color palette (and other settings, like default line width) is read from user preferences but can be changed after object is created.

class sleap.gui.color.ColorManager(labels: = None, palette: str = 'standard')[source]

Class to determine color to use for track.

The color depends on the order of the tracks in Labels object, so we need to initialize with Labels.

  • labels – The Labels dataset which contains the tracks for which we want colors.

  • palette – String with the color palette name to use.

static color_to_tuple(color: Union[str, Iterable[int]]) → Tuple[int, int, int][source]

Convert and ensure color is (r, g, b)-tuple.

fix_index(idx: int) → int[source]

Returns an index within range of color palette.

get_color_by_idx(idx: int) → Tuple[int, int, int][source]

Returns color tuple corresponding to item index.

get_item_color(item: Any, parent_instance: Optional[sleap.instance.Instance] = None, parent_skeleton: Optional[Skeleton] = None) → Tuple[int, int, int][source]

Gets (r, g, b) tuple of color to use for drawing item.

get_item_pen_width(item: Any, parent_instance: Optional[sleap.instance.Instance] = None) → float[source]

Gets width of pen to use for drawing item.

get_item_type_pen_width(item_type: str) → float[source]

Gets pen width to use for given item type (as string).

get_pseudo_track_index(instance: sleap.instance.Instance) → Union[sleap.instance.Track, int][source]

Returns an index for giving track colors to instances without track.

get_track_color(track: Union[sleap.instance.Track, int]) → Tuple[int, int, int][source]

Returns the color to use for a given track.


trackTrack object or an int


(r, g, b)-tuple

classmethod is_edge(item) → bool[source]

Returns whether item is an edge, i.e., pair of nodes.

static is_node(item) → bool[source]

Returns whether item is a node, i.e., Node or node name.

static is_predicted(instance) → bool[source]

Returns whether instance is predicted.

classmethod is_sequence(item) → bool[source]

Returns whether item is a tuple or list.

property labels

Gets or sets labels dataset for which we are coloring tracks.

property palette

Gets or sets palette (by name).

property palette_names

Gets list of palette names.

set_palette(palette: Union[str, Iterable[str]])[source]

Functional alias for palette property setter.

property tracks

Gets tracks for project.