grassp.pl.embedding_prob#
- embedding_prob(adata, basis, color, color_prob, *, cmap='viridis', palette=None, na_color='lightgray', na_in_legend=True, size=None, marker='.', vmin=None, vmax=None, vcenter=None, norm=None, prob_vmin=None, prob_vmax=None, alpha_min=0.05, alpha_max=1.0, opacity_color='black', sort_order=True, legend_loc='right margin', legend_fontsize=None, legend_fontweight='bold', legend_fontoutline=None, colorbar_loc='right', frameon=True, title=None, ax=None, figsize=(7, 5), show=True)[source]#
Scatter plot of an embedding where colour encodes one variable and per-point opacity encodes another.
Each observation is drawn at its position in
adata.obsm[basis], coloured according toadata.obs[color]and made transparent in proportion toadata.obs[color_prob]. A standard colour legend (categorical) or colourbar (numeric) is drawn forcolor, and a separate opacity colourbar (a fade fromalpha_mintoalpha_maxat a fixed reference colour) is drawn forcolor_prob.- Parameters:
- adata
AnnData anndata.AnnDatawith the embedding stored in.obsm[basis](or.obsm[f"X_{basis}"]) and bothcolorandcolor_probpresent in.obs.- basis
str Key in
adata.obsm. Both"umap"and"X_umap"are accepted.- color
str Single
.obscolumn for point colour. May be categorical, boolean, string, or numeric.- color_prob
str Numeric
.obscolumn whose values map to per-point opacity. Higher values → more opaque.- cmap
str(default:'viridis') Matplotlib colormap name used when
coloris numeric.- palette
list|None(default:None) Optional list of colours for categorical
color. WhenNone,adata.uns[f"{color}_colors"]is used if present, otherwise matplotlib’s defaulttab20.- na_color
str(default:'lightgray') Colour for observations whose
colorvalue is NaN. Default"lightgray"(matches scanpy).- na_in_legend
bool(default:True) If
True(default) and the data contain NaN, append an"NA"entry to the categorical legend.- size
float|None(default:None) Marker size. Defaults to a value scaled by
n_obs.- marker
str(default:'.') Matplotlib marker style.
- vmin
float|str|None(default:None) Limits and optional centre for the colour scale (numeric
coloronly). May be a float, a percentile string (e.g."p5","p99.9"), or a callablef(values) -> float.vcentertriggers aTwoSlopeNorm, useful for diverging cmaps.- vmax
float|str|None(default:None) Limits and optional centre for the colour scale (numeric
coloronly). May be a float, a percentile string (e.g."p5","p99.9"), or a callablef(values) -> float.vcentertriggers aTwoSlopeNorm, useful for diverging cmaps.- vcenter
float|str|None(default:None) Limits and optional centre for the colour scale (numeric
coloronly). May be a float, a percentile string (e.g."p5","p99.9"), or a callablef(values) -> float.vcentertriggers aTwoSlopeNorm, useful for diverging cmaps.- norm
Normalize|None(default:None) Explicit
Normalizeinstance, overridingvmin/vmax/vcenter.- prob_vmin
float|str|None(default:None) Limits for the opacity scale. Same flexible types as
vmin/vmax.Noneusescolor_probmin/max.- prob_vmax
float|str|None(default:None) Limits for the opacity scale. Same flexible types as
vmin/vmax.Noneusescolor_probmin/max.- alpha_min
float(default:0.05) Output opacity range for
color_prob.alpha_minis applied to the smallest displayed value,alpha_maxto the largest.- alpha_max
float(default:1.0) Output opacity range for
color_prob.alpha_minis applied to the smallest displayed value,alpha_maxto the largest.- opacity_color
str(default:'black') Reference colour used to render the opacity colourbar (a fade from the figure’s facecolor to fully solid). Pure visual choice; doesn’t affect any plotted point colours.
- sort_order
bool(default:True) If
True(default), points are sorted bycolor_probascending so high-confidence points render on top of low-confidence ones — important when per-point alpha is in play. IfFalse, points are plotted inadata.obsorder.- legend_loc
str(default:'right margin') Location of the categorical colour legend.
"right margin"(default) places it outside the axes on the right;"on data"overlays the category name at each cluster’s centroid;"none"suppresses the categorical legend; any other matplotlib location string ("best","upper left", …) is passed through. Numeric colour always usescolorbar_locinstead.- legend_fontsize
float|str|None(default:None) Font size of legend text and
"on data"labels.Noneuses matplotlib’srcParams["legend.fontsize"].- legend_fontweight
str|int(default:'bold') Font weight of
"on data"labels. Default"bold"(matches scanpy).- legend_fontoutline
float|None(default:None) Width (in points) of a white outline drawn around
"on data"labels for legibility on top of points. Only used whenlegend_loc="on data".Nonedisables the outline.- colorbar_loc
Optional[Literal['right','left','top','bottom']] (default:'right') Where to place the numeric colour colourbar (
"right" | "left" | "top" | "bottom").Nonesuppresses the colourbar; the opacity colourbar is unaffected. Ignored for categoricalcolor.- frameon
bool(default:True) If
True(default), keep axis labels (matching scanpy). IfFalse, hide all spines and axis labels. Ticks are always hidden.- title
str|None(default:None) Plot title. Defaults to
f"{color} (opacity ~ {color_prob})".- ax
Axes|None(default:None) Existing matplotlib axes to draw into. If
None, a new figure is created.- figsize
tuple[float,float] (default:(7, 5)) Figure size when
axis None.- show
bool(default:True) If
True, callplt.show()at the end.
- adata
- Return type:
Axes- Returns:
matplotlib.axes.Axes The axes containing the scatter.