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 a given cell type.

This function visualizes gene expression for a selected cell type along a continuous axis (e.g., pseudotime, spatial coordinate, etc.). It creates a grid of subplots with scatter plots, optional regression fits, and marginal KDE plots for both the axis and gene expression.

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

  • axis – Observation key in adata.obs to plot along the x-axis (e.g., pseudotime).

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

  • cell_type_column – Column name in adata.obs that contains cell type annotations.

  • cell_type – Specific cell type to filter the data for plotting.

  • xlim (Tuple[Union[int, float], Union[int, float]], optional) – Limits for the x-axis. Defaults to (0, np.inf).

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

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

  • fit_reg (bool, optional) – Whether to fit a LOESS regression line to the scatter plot. Defaults to False.

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

  • max_cols (int, optional) – Maximum number of columns in the subplot grid. The actual number of columns will be the minimum of this value and the number of genes. Defaults to 4.

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

  • save_only (bool, optional) – If True, the figure is saved but not shown. Defaults to False.

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

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

  • fig_marginal_ratio (Number, optional) – Height ratio of the marginal KDE plot to the main plot. Defaults to 0.15.

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

  • wspace (Number, optional) – Width space between subplots. Defaults to 0.15.

  • hspace (Number, optional) – Height space 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 plot.

Return type:

None