temporal_expression#
- scdiffeq.plotting._temporal_expression.temporal_expression(adata_sim: AnnData, gene: str, groupby: str = 'final_state', groups: List[str] | None = None, use_key: str = 'X_gene_inv', time_key: str = 't', gene_ids_key: str = 'gene_ids', show_std: bool = True, std_alpha: float = 0.2, ax: Axes | None = None, figsize: tuple = (3, 2.5), cmap: Dict[str, str] | None = None, linewidth: float = 2.0, x_label: str = 't(d)', y_label: str = 'Log-norm. expression', title: str | None = None, show_legend: bool = True, legend_loc: str | tuple = 'best', grid: bool = True, grid_alpha: float = 0.3, save: bool = False, savename: str | None = None, save_format: str = 'svg', dpi: int = 300) Axes[source]#
Plot gene expression over simulated time, grouped by fate.
Computes mean and standard deviation at each time step and plots as line (mean) with shaded fill-between region (±1 std).
- Parameters:
adata_sim (AnnData) – Simulated data from
sdq.tl.simulate(), with gene expression stored in obsm after callingsdq.tl.invert_scaled_gex().gene (str) – Gene name to plot.
groupby (str, default="final_state") – Column in
adata_sim.obsfor grouping trajectories (e.g., cell fate).groups (List[str], optional) – Specific groups to plot. If None, plots all groups. Use this to exclude certain groups (e.g.,
groups=["Mon.", "Neu."]to only plot those two fates).use_key (str, default="X_gene_inv") – Key in
adata_sim.obsmcontaining the gene expression matrix.time_key (str, default="t") – Column in
adata_sim.obscontaining time values.gene_ids_key (str, default="gene_ids") – Key in
adata_sim.unscontaining gene names array.show_std (bool, default=True) – Whether to show standard deviation as shaded fill-between region.
std_alpha (float, default=0.2) – Transparency of the standard deviation shading.
ax (plt.Axes, optional) – Matplotlib axes to plot on. If None, creates new figure.
figsize (tuple, default=(3, 2.5)) – Figure size (width, height) in inches if creating new figure.
cmap (Dict[str, str], optional) – Mapping from group names to colors. If None, uses default colormap.
linewidth (float, default=2.0) – Width of the mean line.
x_label (str, default="t(d)") – Label for x-axis.
y_label (str, default="Log-norm. expression") – Label for y-axis.
title (str, optional) – Plot title. If None, uses gene name in italic.
show_legend (bool, default=True) – Whether to show legend.
legend_loc (str or tuple, default="best") – Legend location.
grid (bool, default=True) – Whether to show grid.
grid_alpha (float, default=0.3) – Transparency of grid lines.
save (bool, default=False) – Whether to save the figure.
savename (str, optional) – Filename for saving. If None, auto-generates from gene name.
save_format (str, default="svg") – Format for saving figure.
dpi (int, default=300) – Resolution for saving figure.
- Returns:
The matplotlib axes object.
- Return type:
plt.Axes
Examples
>>> import scdiffeq as sdq >>> adata_sim = sdq.tl.simulate(adata, diffeq=model, idx=idx) >>> sdq.tl.invert_scaled_gex(adata_sim, ...) >>> sdq.tl.annotate_cell_fate(adata_sim, ...) >>> sdq.pl.temporal_expression( ... adata_sim, ... gene="Spi1", ... groupby="final_state", ... cmap={"Mon.": "orange", "Neu.": "#4a7298"} ... )