cassiopeia.pl.plot_matplotlib#

cassiopeia.pl.plot_matplotlib(tree, depth_key=None, meta_data=None, allele_table=None, indel_colors=None, indel_priors=None, orient=90.0, extend_branches=True, angled_branches=True, add_root=False, figsize=(7.0, 7.0), colorstrip_width=None, colorstrip_spacing=None, clade_colors=None, internal_node_kwargs=None, leaf_kwargs=None, branch_kwargs=None, colorstrip_kwargs=None, continuous_cmap='viridis', vmin=None, vmax=None, categorical_cmap='tab10', value_mapping=None, ax=None, random_state=None)[source]#

Generate a static plot of a tree using Matplotlib.

Parameters:
tree CassiopeiaTree

The CassiopeiaTree to plot.

depth_key Optional[str] (default: None)

The node attribute to use as the depth of the nodes. If not provided, the distances from the root is used by calling tree.get_distances.

meta_data Optional[List[str]] (default: None)

Meta data to plot alongside the tree, which must be columns in the CassiopeiaTree.cell_meta variable.

allele_table Optional[DataFrame] (default: None)

Allele table to plot alongside the tree.

indel_colors Optional[DataFrame] (default: None)

Color mapping to use for plotting the alleles for each cell. Only necessary if allele_table is specified.

indel_priors Optional[DataFrame] (default: None)

Prior probabilities for each indel. Only useful if an allele table is to be plotted and indel_colors is None.

orient Union[Literal['down', 'up', 'left', 'right'], float] (default: 90.0)

The orientation of the tree. Valid arguments are left, right, up, down to display a rectangular plot (indicating the direction of going from root -> leaves) or any number, in which case the tree is placed in polar coordinates with the provided number used as an angle offset. Defaults to 90.

extend_branches bool (default: True)

Extend branch lengths such that the distance from the root to every node is the same. If depth_key is also provided, then only the leaf branches are extended to the deepest leaf.

angled_branches bool (default: True)

Display branches as angled, instead of as just a line from the parent to a child.

add_root bool (default: False)

Add a root node so that only one branch connects to the start of the tree. This node will have the name synthetic_root.

figsize Tuple[float, float] (default: (7.0, 7.0))

Size of the plot. Defaults to (7., 7.,)

colorstrip_width Optional[float] (default: None)

Width of the colorstrip. Width is defined as the length in the direction of the leaves. Defaults to 5% of the tree depth.

colorstrip_spacing Optional[float] (default: None)

Space between consecutive colorstrips. Defaults to half of colorstrip_width.

clade_colors Optional[Dict[str, Tuple[float, float, float]]] (default: None)

Dictionary containing internal node-color mappings. These colors will be used to color all the paths from this node to the leaves the provided color.

internal_node_kwargs Optional[Dict] (default: None)

Keyword arguments to pass to plt.scatter when plotting internal nodes.

leaf_kwargs Optional[Dict] (default: None)

Keyword arguments to pass to plt.scatter when plotting leaf nodes.

branch_kwargs Optional[Dict] (default: None)

Keyword arguments to pass to plt.plot when plotting branches.

colorstrip_kwargs Optional[Dict] (default: None)

Keyword arguments to pass to plt.fill when plotting colorstrips.

continuous_cmap Union[str, Colormap] (default: 'viridis')

Colormap to use for continuous variables. Defaults to viridis.

vmin Optional[float] (default: None)

Value representing the lower limit of the color scale. Only applied to continuous variables.

vmax Optional[float] (default: None)

Value representing the upper limit of the color scale. Only applied to continuous variables.

categorical_cmap Union[str, Colormap] (default: 'tab10')

Colormap to use for categorical variables. Defaults to tab10.

value_mapping Optional[Dict[str, int]] (default: None)

An optional dictionary containing string values to their integer mappings. These mappings are used to assign colors by calling the cmap with the designated integer mapping. By default, the values are assigned pseudo-randomly (whatever order the set() operation returns). Only applied for categorical variables.

ax Optional[Axes] (default: None)

Matplotlib axis to place the tree. If not provided, a new figure is initialized.

random_state Optional[RandomState] (default: None)

A random state for reproducibility

Return type:

Tuple[Figure, Axes]

Returns:

If ax is provided, ax is returned. Otherwise, a tuple of (fig, ax)

of the newly initialized figure and axis.