scanpy.pl.MatrixPlot.add_dendrogram

scanpy.pl.MatrixPlot.add_dendrogram#

MatrixPlot.add_dendrogram(*, show=True, dendrogram_key=None, size=0.8)[source]#

Show dendrogram based on the hierarchical clustering between the groupby categories. Categories are reordered to match the dendrogram order.

The dendrogram information is computed using scanpy.tl.dendrogram(). If sc.tl.dendrogram has not been called previously the function is called with default parameters.

The dendrogram is by default shown on the right side of the plot or on top if the axes are swapped.

var_names are reordered to produce a more pleasing output if:
  • The data contains var_groups

  • the var_groups match the categories.

The previous conditions happen by default when using Plot to show the results from rank_genes_groups() (aka gene markers), by calling scanpy.tl.rank_genes_groups_(plot_name).

Parameters:
show bool | None (default: True)

Boolean to turn on (True) or off (False) ‘add_dendrogram’

dendrogram_key str | None (default: None)

Needed if sc.tl.dendrogram saved the dendrogram using a key different than the default name.

size float | None (default: 0.8)

size of the dendrogram. Corresponds to width when dendrogram shown on the right of the plot, or height when shown on top. The unit is the same as in matplotlib (inches).

Return type:

Self

Returns:

Returns self for method chaining.

Examples

>>> import scanpy as sc
>>> adata = sc.datasets.pbmc68k_reduced()
>>> markers = {'T-cell': 'CD3D', 'B-cell': 'CD79A', 'myeloid': 'CST3'}
>>> plot = sc.pl._baseplot_class.BasePlot(adata, markers, groupby='bulk_labels').add_dendrogram()
>>> plot.plot_group_extra  
{'kind': 'dendrogram',
 'width': 0.8,
 'dendrogram_key': None,
 'dendrogram_ticks': array([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5])}