deepspatial.vis_utils.plot_z_distribution

deepspatial.vis_utils.plot_z_distribution#

deepspatial.vis_utils.plot_z_distribution(adata: AnnData, color_col: str = 'cell_class', palette: Dict[str, str] | None = None, spatial_key: str = 'spatial', z_key: str = 'z_coord', n_points: int = 200, smooth_sigma: float = 3.0, fig_height: float = 3.5, width_per_z_unit: float = 0.05, x_range: Tuple[float, float] | None = None, y_range: Tuple[float, float] | None = None, z_range: Tuple[float, float] | None = None, show_legend: bool = True, save_pdf: str | None = None, show: bool = True) Figure | None[source]#

Render a smoothed stacked area chart representing cell proportions along the Z-axis.

Parameters:
  • adata (ad.AnnData) – Annotated data matrix.

  • color_col (str) – Column in adata.obs representing the cell category.

  • palette (dict, optional) – Mapping of categories to colors.

  • spatial_key (str) – Key in adata.obsm for XY coordinates.

  • z_key (str) – Key in adata.obs for Z coordinate.

  • n_points (int) – Number of interpolation bins along the Z-axis.

  • smooth_sigma (float) – Standard deviation for the Gaussian smoothing kernel.

  • fig_height (float) – Fixed height of the figure in inches.

  • width_per_z_unit (float) – Dynamic width scaling factor (inches per unit of Z-axis span).

  • x_range (tuple of float, optional) – (min, max) coordinates to mask the data before analysis.

  • y_range (tuple of float, optional) – (min, max) coordinates to mask the data before analysis.

  • z_range (tuple of float, optional) – (min, max) coordinates to mask the data before analysis.

  • show_legend (bool) – Whether to draw the category legend.

  • save_pdf (str, optional) – Path to save PDF output.

  • show (bool) – If True, display the plot immediately.

Returns:

Figure object if show=False, else None.

Return type:

matplotlib.figure.Figure or None