mtopic.pl.topics

Contents

mtopic.pl.topics#

mtopic.pl.topics(mdata, x, topics='topics', cmap='gnuplot', marker='.', s=10, vmax=None, fontsize=10, figsize=None, transparent=False, save=None)#

Visualize topic distributions on spatial coordinates or embedding.

This function generates scatter plots to visualize the topic distributions across cells/spots. Each topic is displayed in a separate subplot, showing how the topic is spatially distributed or distributed within a specified embedding. The plots are arranged in a grid for easy comparison.

Parameters:
  • mdata (muon.MuData) – A MuData object containing multimodal single-cell data, with topic distributions stored in obsm.

  • x (str) – The key in obsm of mdata representing the spatial coordinates or embeddings to use for plotting (e.g., UMAP, PCA, or spatial coordinates).

  • topics (str, optional) – The key in obsm of mdata representing the topic distributions to plot. Default is ‘topics’.

  • cmap (str, optional) – Colormap to use for visualizing topic distributions. Default is ‘gnuplot’.

  • marker (str, optional) – Marker style for scatter plots. Default is ‘.’.

  • s (int, optional) – Marker size in scatter plots. Default is 10.

  • vmax (float, optional) – Maximum value for the color scale. If None, it is set to the 99.9th percentile of the data for each topic. Default is None.

  • fontsize (int, optional) – Font size for plot titles and colorbar ticks. Default is 10.

  • figsize (tuple, optional) – Tuple specifying the figure size (width, height) in inches. If None, the size is automatically determined based on the number of topics. Default is None.

  • transparent (bool, optional) – Whether to make the figure background transparent. Useful for overlays in presentations. Default is False.

  • save (str, optional) – Path to save the figure. If None, the figure is displayed but not saved. Default is None.

Returns:

None

Example:
import mtopic

# Load MuData object
mdata = mtopic.read.h5mu("path/to/file.h5mu")

# Plot spatial distribution of topics using UMAP coordinates
mtopic.pl.topics(
    mdata,
    x='umap',
    topics='topics',
    cmap='viridis',
    marker='o',
    s=20,
    fontsize=12
)

# Save the figure to a file
mtopic.pl.topics(
    mdata,
    x='umap',
    topics='topics',
    save='topics_distribution.pdf'
)