spatialScatterPlot
spatialScatterPlot ¶
spatialScatterPlot(
data,
colorBy,
topLayer=None,
xCoordinate="X_centroid",
yCoordinate="Y_centroid",
imageId="imageid",
layer=None,
subset=None,
s=None,
ncols=None,
alpha=1,
dpi=200,
fontSize=None,
plotLegend=True,
cmap="RdBu_r",
catCmap="tab20",
vmin=None,
vmax=None,
customColors=None,
figsize=(5, 5),
invertYaxis=True,
outputDir=None,
fileName="scimapScatterPlot.png",
show=True,
returnData=False,
returnFig=False,
transparent=False,
sdataTable=None,
**kwargs
)
Scatter cells at their tissue coordinates, coloured by anything.
One panel per entry in colorBy. Each key is looked up in obs first, then in
var_names, so colorBy="phenotype" and colorBy="CD45" both work. Numeric
values get a continuous colormap and a colourbar; categorical values get a
discrete palette and a legend.
The y axis is inverted by default, because image coordinates count downwards from the top-left corner — without that the tissue appears mirrored relative to the raw image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
(AnnData | SpatialData | str, required)
|
The cell table. An |
required |
colorBy
|
(str | list, required)
|
What to colour by. Each entry may be an |
required |
topLayer
|
list
|
Accepted for signature compatibility with scimap; the current implementation draws categories in sorted order. |
None
|
xCoordinate
|
str
|
Column in |
'X_centroid'
|
yCoordinate
|
str
|
Column in |
'Y_centroid'
|
imageId
|
str
|
Column in |
'imageid'
|
layer
|
str
|
Which matrix to read marker values from. |
None
|
subset
|
str | list
|
Restrict to these images. Plotting a whole multi-image object at once is rarely useful. |
None
|
s
|
float
|
Point size. Defaults to 5. Lower it to 1-3 for dense slides. |
None
|
ncols
|
int
|
Panels per row. Defaults to |
None
|
alpha
|
float
|
Point opacity. |
1
|
dpi
|
int
|
Resolution of the saved figure. |
200
|
fontSize
|
int
|
Title and legend font size. |
None
|
plotLegend
|
bool
|
Draw the legend for categorical colours. |
True
|
cmap
|
str
|
Colormap for numeric values. |
'RdBu_r'
|
catCmap
|
str
|
Colormap used to build the discrete palette for categorical values. |
'tab20'
|
vmin
|
float
|
Lower colour limit for numeric values. |
None
|
vmax
|
float
|
Upper colour limit for numeric values. |
None
|
customColors
|
dict
|
Explicit |
None
|
figsize
|
tuple
|
Size of a single panel in inches. |
(5, 5)
|
invertYaxis
|
bool
|
Invert the y axis so the plot matches the orientation of the raw image. |
True
|
outputDir
|
str
|
Directory to save the figure in. |
None
|
fileName
|
str
|
File name for the saved figure. |
'scimapScatterPlot.png'
|
show
|
bool
|
Call |
True
|
returnData
|
bool
|
Return the plotted |
False
|
returnFig
|
bool
|
Return |
False
|
transparent
|
bool
|
Save with a transparent background. |
False
|
sdataTable
|
str
|
Which |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
result |
None | DataFrame | tuple
|
|
Example
# Phenotypes in one image.
sp.pl.spatialScatterPlot(adata, colorBy="phenotype", subset="sample_1", s=3)
# Two markers side by side.
sp.pl.spatialScatterPlot(adata, colorBy=["CD45", "ECAD"], layer="rescaled")
# Fixed colours for the phenotypes that matter.
sp.pl.spatialScatterPlot(
adata,
colorBy="phenotype",
customColors={"Treg": "#e41a1c", "ECAD+": "#377eb8"},
outputDir="figures",
show=False,
)