troutpy.pl.celltype_contact_matrix

troutpy.pl.celltype_contact_matrix#

troutpy.pl.celltype_contact_matrix(mat, sdata=None, kind='heatmap', cell_type_key='leiden', cmap='BuPu', vmin=None, vmax=None, dendrogram_ratio=0.1, title='Cell-type contact matrix', palette='tab20', **kwargs)#

Plot a cell type x cell type contact matrix as a heatmap or chord diagram.

Parameters:
  • mat (DataFrame) – Square contact matrix, as returned by troutpy.tl.celltype_contact_matrix(), with rows as source cell types and columns as neighbour cell types.

  • sdata (Optional[SpatialData] (default: None)) – If provided, cell-type colors are taken from sdata["table"].uns[cell_type_key + "_colors"]. Otherwise, palette is used as a fallback.

  • kind (str (default: 'heatmap')) – Type of plot, either "heatmap" (seaborn.clustermap()) or "chord" (mpl_chord_diagram.chord_diagram()).

  • cell_type_key (str (default: 'leiden')) – Key in sdata["table"].obs/.uns used to resolve per-cell-type colors.

  • cmap (str (default: 'BuPu')) – Colormap for the heatmap.

  • vmin (Optional[float] (default: None)) – Min value for colormap scaling.

  • vmax (Optional[float] (default: None)) – Max value for colormap scaling.

  • dendrogram_ratio (float (default: 0.1)) – Passed to seaborn.clustermap().

  • title (str (default: 'Cell-type contact matrix')) – Figure title.

  • palette (str (default: 'tab20')) – Matplotlib colormap name used as a fallback when sdata is None or has no stored colors for cell_type_key.

  • kwargs – Additional arguments passed to seaborn.clustermap() or mpl_chord_diagram.chord_diagram().

Returns:

For kind="heatmap", the seaborn.matrix.ClusterGrid. For kind="chord", the matplotlib.figure.Figure.