pycea.pl.annotation#
- pycea.pl.annotation(tdata, keys=None, width=0.05, gap=0.03, label=True, layer=None, border_width=0, legend=None, tree=None, cmap=None, palette=None, vmax=None, vmin=None, share_cmap=False, na_color='white', slot=None, ax=None, legend_kwargs=None, **kwargs)#
Plot leaf annotations for a tree.
Plots one or more leaf annotations (small heatmap-like bars) next to the tree’s leaves, preserving the leaf order/layout used by
pycea.pl.branches(). Each key can be continuous (colored via acolormap) or categorical (colored via apalette). Multiple keys are stacked horizontally (or radially if your tree plot is polar).- Parameters:
tdata (
TreeData) – The TreeData object.keys (
str|Sequence[str] |None(default:None)) – One or moreobs.keys(),var_names,obsm.keys(), orobsp.keys()to plot.width (
float(default:0.05)) – The width of the annotation bar relative to the tree.gap (
float(default:0.03)) – The gap between the annotation bar and the tree relative to the tree.label (
bool|str|Sequence[str] |None(default:True)) – Annotation labels. IfTrue, the keys are used as labels. If a string or a sequence of strings, the strings are used as labels.layer (
str|None(default:None)) – Name of the TreeData object layer to use. IfNone,tdata.Xis plotted.border_width (
float(default:0)) – The width of the border around the annotation bar.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.share_cmap (
bool(default:False)) – IfTrue, all numeric keys will share the same colormap.na_color (
str(default:'white')) – The color to use for annotations with missing data.slot (
Optional[Literal['obs','obsm','obsp','X']] (default:None)) – Slot in TreeData object containingkeys. IfNone, searchesobs,X,obsm, andobspin that order.ax (
Axes|None(default:None)) – A matplotlib axes object. IfNone, a new figure and axes will be created.legend_kwargs (
dict[str,Any] |None(default:None)) – Additional keyword arguments passed tomatplotlib.pyplot.legend().kwargs – Additional keyword arguments passed to
matplotlib.pyplot.pcolormesh().
- 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 leaf annotations for “elt-2” and “pal-1” expression:
>>> tdata = py.datasets.packer19(tree = "observed") >>> py.pl.branches(tdata, depth_key="time") >>> py.pl.annotation(tdata, keys=["elt-2", "pal-1"])
Plot leaf annotation for spatial distance between leaves:
>>> py.tl.distance(tdata, key = "spatial") >>> py.pl.branches(tdata, depth_key="time") >>> py.pl.annotation(tdata, keys="spatial_distances", cmap="magma")