drvi.utils.plotting.plot_latent_dimension_stats

drvi.utils.plotting.plot_latent_dimension_stats#

drvi.utils.plotting.plot_latent_dimension_stats(embed, figsize=(5, 3), log_scale='try', ncols=5, columns=('reconstruction_effect', 'max_value', 'mean', 'std'), titles=None, remove_vanished=False, show=True)[source]#

Plot the statistics of latent dimensions.

This function creates line plots showing various statistics of latent dimensions across their ranking order. It can optionally distinguish between vanished and non-vanished dimensions.

Parameters:
  • embed (AnnData) – Annotated data object containing the latent dimensions and their statistics in the .var attribute.

  • figsize (tuple[int, int] (default: (5, 3))) – The size of each subplot (width, height) in inches.

  • log_scale (bool | Literal['try'] (default: 'try')) – Whether to use a log scale for the y-axis. If “try”, log scale is used only if the minimum value is greater than 0.

  • ncols (int (default: 5)) – The maximum number of columns in the subplot grid.

  • columns (Sequence[str] (default: ('reconstruction_effect', 'max_value', 'mean', 'std'))) – The columns from embed.var to plot. These should be numeric columns containing dimension statistics.

  • titles (dict[str, str] | None (default: None)) – Custom titles for each column in the plot. If None, default titles are used.

  • remove_vanished (bool (default: False)) – Whether to exclude vanished dimensions from the plot.

  • show (bool (default: True)) – Whether to display the plot. If False, returns the figure object.

Returns:

matplotlib.figure.Figure or None The matplotlib figure object if show=False, otherwise None.

Notes

The function expects the following columns in embed.var: - order: Ranking of dimensions - vanished: Boolean indicating vanished dimensions - The columns specified in the columns parameter

If remove_vanished=False, a legend is added to distinguish between vanished (black dots) and non-vanished (blue dots) dimensions.

Examples

>>> # Default plot
>>> plot_latent_dimension_stats(embed)
>>>
>>> # Plot basic statistics
>>> plot_latent_dimension_stats(embed, columns=["reconstruction_effect", "max_value"])
>>> # Plot with custom titles and log scale
>>> titles = {"reconstruction_effect": "Reconstruction Impact", "max_value": "Max Activation"}
>>> plot_latent_dimension_stats(embed, titles=titles, log_scale=True)