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 str | NoneOptional[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 List[str] | NoneOptional[List[str]] (default: None)

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

allele_table DataFrame | NoneOptional[DataFrame] (default: None)

Allele table to plot alongside the tree.

indel_colors DataFrame | NoneOptional[DataFrame] (default: None)

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

indel_priors DataFrame | NoneOptional[DataFrame] (default: None)

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

orient Literal['down', 'up', 'left', 'right'] | floatUnion[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 float | NoneOptional[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 float | NoneOptional[float] (default: None)

Space between consecutive colorstrips. Defaults to half of colorstrip_width.

clade_colors {str: Tuple[float, float, float]} | NoneOptional[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 Dict | NoneOptional[Dict] (default: None)

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

leaf_kwargs Dict | NoneOptional[Dict] (default: None)

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

branch_kwargs Dict | NoneOptional[Dict] (default: None)

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

colorstrip_kwargs Dict | NoneOptional[Dict] (default: None)

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

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

Colormap to use for continuous variables. Defaults to viridis.

vmin float | NoneOptional[float] (default: None)

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

vmax float | NoneOptional[float] (default: None)

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

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

Colormap to use for categorical variables. Defaults to tab10.

value_mapping {str: int} | NoneOptional[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 Axes | NoneOptional[Axes] (default: None)

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

random_state RandomState | NoneOptional[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.