pycea.pl.branches#
- pycea.pl.branches(tdata, polar=False, extend_branches=False, angled_branches=False, angle_range=(0, 360), color='black', linewidth=0.5, depth_key=None, legend=None, tree=None, cmap='viridis', palette=None, vmax=None, vmin=None, na_color='lightgrey', na_linewidth=1, linewidths=(0.1, 2), slot=None, ax=None, legend_kwargs=None, **kwargs)#
Plot the branches of a tree.
Plots the branches of one or more trees stored in
tdata.obstas amatplotlib.collections.LineCollection. Branch appearance (colorandlinewidth) can be fixed scalars or set based on edge attributes (continuous or categorical). Coloring of continuous variables is based on a colormap (cmap), while categorical variables can be colored using a custompaletteor a default categorical color set. Polar coordinates are used whenpolaris True.- Parameters:
tdata (
TreeData) – Thetreedata.TreeDataobject.polar (
bool(default:False)) – Whether to plot the tree in polar coordinates.extend_branches (
bool(default:False)) – Whether to extend branches so the tips are at the same depth.angled_branches (
bool(default:False)) – Whether to plot branches at an angle.angle_range (
tuple[float,float] (default:(0, 360))) – A(start, end)tuple in degrees specifying the arc span for polar plots. Defaults to(0, 360)for a full circle. Use a smaller range (e.g.(0, 180)) to generate a “pie slice” shaped tree. Only used whenpolar=True.color (
str(default:'black')) – Either a color name, or a key for an attribute of the edges to color by.linewidth (
float|str(default:0.5)) – Either an numeric width, or a key for an attribute of the edges to set the linewidth.depth_key (
str|None(default:None)) – The key for the depth of the nodes.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(default:'viridis')) – 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.na_color (
str(default:'lightgrey')) – The color to use for edges with missing data.na_linewidth (
float(default:1)) – The linewidth to use for edges with missing data.slot (
Optional[Literal['obst','obsp']] (default:None)) – Slot in TreeData object containingcolorandlinewidthattributes. IfNone, searchesobstwhenalignment='leaves', searchesobstandobspotherwise.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.collections.LineCollection.
- Return type:
- Returns:
ax - The axes that the plot was drawn on.
Notes
If
axis provided the coordinate system must match thepolarsetting.Continuous color attributes use
cmapwithvmin/vmaxnormalization.
Examples
Plot tree branches:
>>> tdata = py.datasets.packer19() >>> py.pl.branches(tdata, depth_key="time")
Plot tree branches in polar coordinates, colored by clade:
>>> py.pl.branches(tdata, depth_key="time", polar=True, color="clade")