Skip to content

distPlot

distPlot

distPlot(
    data,
    layer=None,
    markers=None,
    subset=None,
    imageId="imageid",
    vline=None,
    plotGrid=True,
    ncols=None,
    color=None,
    xticks=None,
    figsize=(5, 5),
    fontSize=None,
    dpi=200,
    outputDir=None,
    fileName="scimapDistPlot.png",
    show=True,
    returnData=False,
    returnFig=False,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Per-marker intensity histograms in a grid.

One histogram per marker, drawn from whichever matrix layer selects. Pass vline to draw a candidate gate across every panel — on rescaled data that is usually 0.5.

Parameters:

Name Type Description Default
data (AnnData | SpatialData | str, required)

The cell table. An AnnData, a path to an .h5ad file, a SpatialData object, or a path to a .zarr SpatialData store.

required
layer str

Which matrix to plot. None uses .X, 'raw' uses .raw.X, any other string names a key in .layers.

None
markers list

Markers to plot. All of them when None.

None
subset str | list

Restrict to these values of imageId.

None
imageId str

Column in obs holding image identifiers, used by subset.

'imageid'
vline float

Draw a vertical reference line at this value in every panel.

None
plotGrid bool

Draw a faint grid behind each histogram.

True
ncols int

Panels per row. Defaults to min(4, number of markers).

None
color str

Bar colour.

None
xticks list

Explicit x tick positions.

None
figsize tuple

Size of a single panel in inches; the figure is scaled by the grid.

(5, 5)
fontSize int

Panel title font size.

None
**kwargs dict

Passed through to Axes.hist. bins defaults to 50.

{}
outputDir str

Directory to save the figure in. When None nothing is written.

None
fileName str

File name for the saved figure. The extension decides the format.

'scimapDistPlot.png'
show bool

Call plt.show() before returning. Set False in scripts and notebooks that save rather than display.

True
returnData bool

Return the DataFrame behind the plot instead of drawing it.

False
returnFig bool

Return (fig, axes). With returnData as well, returns (fig, axes, plotData).

False
dpi int

Resolution of the saved figure.

200
transparent bool

Save with a transparent background.

False
sdataTable str

Which SpatialData table to read. Ignored for AnnData input, and optional when the store has exactly one table.

None

Returns:

Name Type Description
result None | DataFrame | tuple

None by default; the cell x marker DataFrame with returnData=True; (fig, axes) with returnFig=True.

Example
# Every marker, with the rescaled 0.5 boundary marked.
sp.pl.distPlot(adata, layer="rescaled", vline=0.5)

# Two markers in one image, saved.
sp.pl.distPlot(
    adata,
    markers=["CD45", "ECAD"],
    subset="sample_1",
    outputDir="figures",
    fileName="gates.png",
    show=False,
)