scbiot.pl.plot_anndata_confusion#
- scbiot.pl.plot_anndata_confusion(adata, true_key, pred_key, *, dropna=True, drop_unknown=True, unknown_values=('unknown',), order_key=None, normalize='pred', figsize=(10, 3.6), cmap='Blues', linewidths=0.5, linecolor='lightgrey', annotate_mapping=True, mapping_fontsize=10, tick_fontsize=14, title=None, return_data=False)#
Plot a confusion-style heatmap comparing two categorical annotations in adata.obs.
Parameters#
- adataAnnData-like
Must have adata.obs as a pandas DataFrame.
- true_keystr
Column in adata.obs for ground-truth labels.
- pred_keystr
Column in adata.obs for predicted labels.
- dropnabool
Drop rows where either label is NA.
- drop_unknownbool
Drop rows where either label matches values in unknown_values (case-insensitive).
- unknown_valuesSequence[str]
Values treated as unknown.
- order_keyOptional[str]
Which column to use for frequency-based ordering. Defaults to true_key.
- normalizestr
“pred” => rows sum to 1 (fraction within predicted class). “true” => columns sum to 1 (fraction within true class). “all” => all entries sum to 1. “none” => raw counts.
- figsize(w, h)
Figure size for the heatmap panel; when annotate_mapping is True, extra height is added.
- cmapstr
Colormap name.
- linewidths, linecolorfloat, str
Heatmap grid styling.
- annotate_mappingbool
Show numeric ticks with side mapping text.
- mapping_fontsize, tick_fontsizeint
Font sizes.
- titleOptional[str]
Title for the heatmap.
- return_databool
If True, also return (counts_df, normalized_df).
Returns#
(fig, ax) or (fig, ax, counts_df, norm_df)
Examples#
Basic usage:
>>> import scbiot as scb >>> fig, ax = scb.pl.plot_anndata_confusion(adata, "true_cell_type", "pred_cell_type")
- Parameters:
- Return type:
Union[Tuple[‘plt.Figure’, ‘plt.Axes’], Tuple[‘plt.Figure’, ‘plt.Axes’, pd.DataFrame, pd.DataFrame]]