pycea.pl.nodes

Contents

pycea.pl.nodes#

pycea.pl.nodes(tdata, nodes='internal', color='black', style='o', size=10, legend=None, tree=None, palette=None, cmap=None, vmax=None, vmin=None, markers=None, sizes=(5, 50), na_color='#FFFFFF00', na_style='none', na_size=0, outline_width=None, slot=None, ax=None, legend_kwargs=None, **kwargs)#

Plot the nodes of a tree.

Plot the nodes of one or more trees from tdata.obst on the current axes using matplotlib.pyplot.scatter(). Appearance can be fixed (single color/marker/size) or set based on node attributes (continuous or categorical). You can plot only leaves, only internal nodes, all nodes, or an explicit list of node names.

Parameters:
  • tdata (TreeData) – The TreeData object.

  • nodes (str | Sequence[str] (default: 'internal')) – Either “all”, “leaves”, “internal”, or a list of nodes to plot.

  • color (str (default: 'black')) – Either a color name, or a key for an attribute of the nodes to color by.

  • style (str (default: 'o')) – Either a marker name, or a key for an attribute of the nodes to set the marker. Can be numeric but will always be treated as a categorical variable.

  • size (float | str (default: 10)) – Either an numeric size, or a key for an attribute of the nodes to set the size.

  • legend (bool | None (default: None)) – Whether to add a legend to the plot. By default, a legend is added if there are <= 20 distinct categories.

  • tree (str | Sequence[str] | None (default: None)) – The obst key or keys of the trees to plot. If None, all trees are plotted.

  • cmap (str | Colormap | None (default: None)) – Color map to use for continous variables. Can be a name or a Colormap instance (e.g. "magma”, "viridis" or mpl.cm.cividis), see get_cmap(). If None, the value of mpl.rcParams["image.cmap"] is used. The default cmap can be set using set_figure_params().

  • palette (Cycler | ListedColormap | Sequence[str] | Mapping[Any, str] | None (default: None)) – Colors to use for plotting categorical annotation groups. The palette can be a valid ListedColormap name ('Set2', 'tab20', …), a Cycler object, a dict mapping categories to colors, or a sequence of colors. Colors must be valid to matplotlib. (see is_color_like()). If None, mpl.rcParams["axes.prop_cycle"] is used unless the categorical variable already has colors stored in tdata.uns["{var}_colors"]. If provided, values of tdata.uns["{var}_colors"] will be set.

  • vmax (float | str | None (default: None)) – The maximum value for the colormap. Use 'p99' to set the maximum to the 99th percentile of the data.

  • vmin (float | str | None (default: None)) – The minimum value for the colormap. Use 'p1' to set the minimum to the 1st percentile of the data.

  • markers (Sequence[str] | Mapping[str, str] | None (default: None)) – Object determining how to draw the markers for different levels of the style variable. You can pass a list of markers or a dictionary mapping levels of the style variable to markers.

  • sizes (tuple[float, float] | Mapping[str, float] (default: (5, 50))) – Object determining how to draw the sizes for different levels of the size variable. You can pass a dictionary mapping levels to sizes, or a min, max tuple to use as a range.

  • na_color (str (default: '#FFFFFF00')) – The color to use for annotations with missing data.

  • na_style (str (default: 'none')) – The marker to use for annotations with missing data.

  • na_size (float (default: 0)) – The size to use for annotations with missing data.

  • outline_width (float | None (default: None)) – Width of a black outline drawn around each node marker. None (default) draws no outline.

  • ax (Axes | None (default: None)) – A matplotlib axes object. If None, a new figure and axes will be created.

  • slot (Optional[Literal['obst', 'obs', 'X']] (default: None)) – Slot in TreeData object containing color, style, and size attributes. If None, searches obst when alignment='leaves', searches obs and X otherwise.

  • legend_kwargs (dict[str, Any] | None (default: None)) – Additional keyword arguments passed to matplotlib.pyplot.legend().

  • kwargs – Additional keyword arguments passed to matplotlib.pyplot.scatter().

Return type:

Axes

Returns:

ax - The axes that the plot was drawn on.

Notes

Examples

Plot internal nodes colored by depth:

>>> tdata = py.datasets.packer19()
>>> py.pl.branches(tdata, depth_key="time")
>>> py.pl.nodes(tdata, nodes="internal", color="time", cmap="plasma")

Color nodes by “elt-2” expression and highlight the “E” node with a star marker:

>>> py.pl.branches(tdata, depth_key="time")
>>> py.pl.nodes(tdata, color="elt-2", nodes="all")
>>> py.pl.nodes(tdata, color="red", nodes="EMS", style="*", size=200, slot="obst")