heatmap
heatmap ¶
heatmap(
data,
groupBy,
layer=None,
subsetMarkers=None,
subsetGroups=None,
clusterRows=True,
clusterColumns=True,
standardScale=None,
orderRow=None,
orderColumn=None,
showPrevalence=False,
cmap="vlag",
figsize=None,
saveDir=None,
outputDir=None,
fileName=None,
verbose=True,
show=True,
returnData=False,
returnFig=False,
dpi=300,
transparent=False,
sdataTable=None,
**kwargs
)
Mean marker expression per group of cells, as a heatmap.
Cells are averaged within each category of groupBy, giving a
group x marker matrix. Rows and columns are hierarchically clustered by
default (average linkage on Euclidean distance), so related phenotypes and
co-expressed markers end up next to each other.
Clustering and manual ordering are mutually exclusive: passing orderRow or
orderColumn together with clusterRows=True or clusterColumns=True raises
a ValueError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
groupBy
|
(str, required)
|
Column in |
required |
layer
|
str
|
Which matrix to average. |
None
|
subsetMarkers
|
list
|
Restrict the columns to these markers. |
None
|
subsetGroups
|
list
|
Restrict the rows to these |
None
|
clusterRows
|
bool
|
Hierarchically cluster the groups. |
True
|
clusterColumns
|
bool
|
Hierarchically cluster the markers. |
True
|
standardScale
|
str
|
|
None
|
orderRow
|
list
|
Explicit group order. Requires |
None
|
orderColumn
|
list
|
Explicit marker order. Requires |
None
|
showPrevalence
|
bool
|
Annotate each row with the number of cells it summarises. |
False
|
cmap
|
str
|
Any Matplotlib colormap name. |
'vlag'
|
figsize
|
tuple
|
Figure size in inches. Scaled from the matrix shape when |
None
|
verbose
|
bool
|
Print progress messages. |
True
|
outputDir
|
str
|
Directory to save the figure in. When |
None
|
fileName
|
str
|
File name for the saved figure. The extension decides the format. |
None
|
saveDir
|
str
|
Deprecated alias for |
None
|
show
|
bool
|
Call |
True
|
returnData
|
bool
|
Return the |
False
|
returnFig
|
bool
|
Return |
False
|
dpi
|
int
|
Resolution of the saved figure. |
300
|
transparent
|
bool
|
Save with a transparent background. |
False
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
None | DataFrame | tuple
|
|
Example
# Phenotypes against the markers that define them.
sp.pl.heatmap(adata, groupBy="phenotype", standardScale="column")
# A fixed marker order, no clustering, saved to disk.
sp.pl.heatmap(
adata,
groupBy="phenotype",
clusterColumns=False,
orderColumn=["CD45", "ECAD", "SMA"],
outputDir="figures",
fileName="phenotype_heatmap.pdf",
show=False,
)
# The underlying numbers, without drawing anything.
means = sp.pl.heatmap(adata, groupBy="phenotype", returnData=True)