insitupy.plotting.cell_expression_along_axis

insitupy.plotting.cell_expression_along_axis#

insitupy.plotting.cell_expression_along_axis(adata, axis, genes, cell_type_column, cell_type, xlim=(0, inf), min_expression=0, xlabel=None, fit_reg=False, kde=False, max_cols=4, savepath=None, save_only=False, dpi_save=300, fig_height=4, fig_marginal_ratio=0.15, scatter_size=1, wspace=0.15, hspace=0.25, font_scale_factor=1)#

Plot gene expression along a specified axis for selected cell types.

This function visualizes gene expression for one or more genes along a continuous axis (e.g., pseudotime, spatial coordinate) for a specified cell type or group of cell types. It generates a grid of subplots with scatter plots, optional LOESS regression fits, and marginal KDE plots for both the axis and gene expression distributions.

Parameters:
  • adata – AnnData object containing single-cell data.

  • axis – Key in adata.obs or a tuple (obsm key, column key) to use for the x-axis.

  • genes (List[str]) – List of gene names to plot.

  • cell_type_column (str) – Column in adata.obs with cell type annotations.

  • cell_type (Union[str, List[str]]) – Cell type(s) to include in the plot.

  • xlim (Tuple[Union[int, float], Union[int, float]], optional) – X-axis limits. Defaults to (0, np.inf).

  • min_expression (Union[int, float], optional) – Minimum expression threshold. Defaults to 0.

  • xlabel (Optional[str], optional) – Custom x-axis label. Defaults to axis name.

  • fit_reg (bool, optional) – Whether to overlay a LOESS regression line. Defaults to False.

  • kde (bool, optional) – Whether to overlay a 2D KDE plot. Defaults to False.

  • max_cols (int, optional) – Maximum number of columns in the subplot grid. Defaults to 4.

  • savepath (Union[str, os.PathLike, Path], optional) – Path to save the figure. Defaults to None.

  • save_only (bool, optional) – If True, saves the figure without displaying it. Defaults to False.

  • dpi_save (int, optional) – DPI for saved figure. Defaults to 300.

  • fig_height (Number, optional) – Height of each subplot row. Defaults to 4.

  • fig_marginal_ratio (Number, optional) – Ratio of marginal KDE height to main plot. Defaults to 0.15.

  • scatter_size (Number, optional) – Size of scatter plot points. Defaults to 1.

  • wspace (Number, optional) – Horizontal spacing between subplots. Defaults to 0.15.

  • hspace (Number, optional) – Vertical spacing between subplot rows. Defaults to 0.25.

  • font_scale_factor (Number, optional) – Scaling factor for font sizes. Defaults to 1.

Returns:

Displays and/or saves the generated figure.

Return type:

None