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.obston the current axes usingmatplotlib.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)) – Theobstkey or keys of the trees to plot. IfNone, all trees are plotted.cmap (
str|Colormap|None(default:None)) – Color map to use for continous variables. Can be a name or aColormapinstance (e.g."magma”,"viridis"ormpl.cm.cividis), seeget_cmap(). IfNone, the value ofmpl.rcParams["image.cmap"]is used. The defaultcmapcan be set usingset_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 validListedColormapname ('Set2','tab20', …), aCyclerobject, a dict mapping categories to colors, or a sequence of colors. Colors must be valid to matplotlib. (seeis_color_like()). IfNone,mpl.rcParams["axes.prop_cycle"]is used unless the categorical variable already has colors stored intdata.uns["{var}_colors"]. If provided, values oftdata.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. IfNone, a new figure and axes will be created.slot (
Optional[Literal['obst','obs','X']] (default:None)) – Slot in TreeData object containingcolor,style, andsizeattributes. IfNone, searchesobstwhenalignment='leaves', searchesobsandXotherwise.legend_kwargs (
dict[str,Any] |None(default:None)) – Additional keyword arguments passed tomatplotlib.pyplot.legend().kwargs – Additional keyword arguments passed to
matplotlib.pyplot.scatter().
- Return type:
- Returns:
ax - The axes that the plot was drawn on.
Notes
Must call
pycea.pl.branches()orpycea.pl.tree()before calling this function.Continuous color attributes use
cmapwithvmin/vmaxnormalization.
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")