heatmap#
- heatmap(data: AnnData, keys: Sequence[str] | Mapping[str, Sequence[str]], group_by: str, *, mapping: FeatureSpec | None = None, geom: Literal['raster', 'tile'] = 'raster', scale_axis: Literal[0, 1] | None = None, dendrogram: bool = False, aggregate: bool = False, group_bars: bool = True, group_bars_size: float = 6, group_bars_labels: bool = True, group_lines: bool = True, group_lines_color: str = 'black', group_lines_size: float = 1.0, dendrogram_color: str = 'black', dendrogram_size: float = 0.5, group_lines_kwargs: dict | None = None, dendrogram_kwargs: dict | None = None, key_labels: bool = True, value_column: str = 'value', variable_column: str = 'variable', color_low: str = '#0000ff', color_mid: str = '#ffffff', color_high: str = '#ff0000', mid_point: Literal['mean', 'median', 'mid'] | float = 'mid', axis: Literal[0, 1] | None = 0, observations_name: str = 'Barcode', variables_name: str = 'Variable', include_dimensions: bool | int = False, interactive: bool = False, **geom_kwargs) PlotSpec#
Heatmap.
- Parameters:
data (
AnnData) – The AnnData object of the single cell data.keys (
Sequence[str] | Mapping[str,Sequence[str]]) – Variable keys to include. When a mapping is provided, each entry maps a group label to the keys belonging to that group; the keys are placed on the x-axis in mapping order. The same key cannot appear in more than one group.group_by (
str) – The key to group the data by.mapping (
FeatureSpec | None, defaultNone) – Aesthetic mappings for the plot, the result of aes().geom (
{'raster', 'tile'}, default'raster') – The geom to use,. Use ‘raster’ for performance. Use ‘tile’ to enable tooltips.dendrogram (
bool, defaultFalse) – Whether to add a dendrogram for thegroup_byaxis. Usesscanpy.tl.dendrogramif not already computed.aggregate (
bool, defaultFalse) – If False, plot one row per observation (i.e., cell). If True, aggregate values per group by mean so each row is a group. For the aggregated view, prefermatrixplot().group_bars (
bool, defaultTrue) – Whether to draw colored vertical bars on the left marking group membership. Only used whenaggregate=False.group_bars_size (
float, default6) – Size (thickness) of the group color bars.group_bars_labels (
bool, defaultTrue) – Whether to show group names as labels along the y-axis. Removes the related legend. Only applies whengroup_bars=Trueandaggregate=False.group_lines (
bool, defaultTrue) – Whether to draw horizontal lines within the heatmap separating groups.group_lines_color (
str, default'black') – Color of the group separator lines.group_lines_size (
float, default1.0) – Size (thickness) of the group separator lines.dendrogram_color (
str, default'black') – Color of the dendrogram segments.dendrogram_size (
float, default0.5) – Size (thickness) of the dendrogram segments.group_lines_kwargs (
dict | None, defaultNone) – Additional parameters to pass to the group separator lines geom_segment.dendrogram_kwargs (
dict | None, defaultNone) – Additional parameters to pass to the dendrogram geom_segment.key_labels (
bool, defaultTrue) – Whether to draw bracket labels above the plot whenkeysis a mapping.scale_axis (
{0, 1}| None, defaultNone) – Whether to standardize a dimension between 0 and 1. Subtracts the minimum and divides by the maximum. If 0, standardize each variable (column). If 1, standardize each row (group whenaggregateis True, observation otherwise).value_column (
str, default'value') – Name for the value column after unpivoting.variable_column (
str, default'variable') – Name for the variable column after unpivoting.color_low (
str, default'#0000ff') – Color for low values in the gradient.color_mid (
str, default'#ffffff') – Color for mid values in the gradient.color_high (
str, default'#ff0000') – Color for high values in the gradient.mid_point (
{'mean', 'median', 'mid'}| float, default'mid') – Midpoint for the color gradient.axis (
{0,1}| None, default0) – Axis of the data, 0 for observations and 1 for variables.observations_name (
str, default'Barcode') – The name of the observations column.variables_name (
str, default'Variable') – Name for the variables index column.include_dimensions (
bool | int, defaultFalse) – Whether to include dimensions in the DataFrame. Providing an integer will limit the number of dimensions to given number.interactive (
bool, defaultFalse) – Whether to make the plot interactive.**geom_kwargs – Additional parameters for the heatmap geom layer.
- Returns:
PlotSpec– Heatmap.
Examples
Heatmap plots one row per observation (cell), grouped by
group_by.import scanpy as sc from lets_plot import * import cellestial as cl data = sc.read("data/pbmc3k_pped.h5ad") markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"] cl.heatmap( data, group_by="cell_type_lvl1", keys=markers, dendrogram=True, ) + scale_fill_viridis()
To enable tooltips, use
geom='tile'.cl.heatmap( data, group_by="cell_type_lvl1", keys=markers, dendrogram=True, geom="tile", tooltips=["value"], ) + scale_fill_viridis()
Values can be standardized per-row or per-column with
scale_axis.cl.heatmap( data, group_by="cell_type_lvl1", keys=markers, dendrogram=True, scale_axis=1, ) + scale_fill_viridis()
Heatmap components (group separator lines, group bars, dendrogram) can be added or customized.
cl.heatmap( data, group_by="cell_type_lvl1", keys=markers, geom="raster", group_lines_size=0.5, group_lines_color="white", dendrogram=True, dendrogram_size="0.7", group_bars_labels=True, group_bars=True, ) + scale_fill_viridis()
For the aggregated view (one row per group), use
matrixplot()or passaggregate=True.cl.heatmap( data, group_by="cell_type_lvl1", keys=markers, aggregate=True, dendrogram=True, )