Skip to content

pie

pie

pie(
    data,
    phenotype="phenotype",
    groupBy="imageid",
    ncols=None,
    subsetPhenotype=None,
    subsetGroupBy=None,
    label="auto",
    title="auto",
    colors=None,
    autopct="%1.1f%%",
    legend=False,
    legendLoc="upper right",
    wedgeprops=None,
    fileName="pie.pdf",
    outputDir=None,
    saveDir=None,
    show=True,
    returnData=False,
    returnFig=False,
    dpi=300,
    transparent=False,
    sdataTable=None,
    **kwargs
)

Cell-type proportions as a grid of pie charts.

One pie per category of groupBy, with wedges for each category of phenotype. The counts behind the plot are a pandas.crosstab of the two columns, which returnData=True hands back.

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
phenotype str

Column in obs that supplies the wedges.

'phenotype'
groupBy str

Column in obs that supplies the panels. One pie per value.

'imageid'
ncols int

Panels per row. Defaults to min(3, number of groups).

None
subsetPhenotype list

Keep only these phenotypes.

None
subsetGroupBy list

Keep only these groups.

None
label str

'auto' labels the wedges with the phenotype names; anything else suppresses the labels.

'auto'
title str

'auto' titles each panel with its group name; any other string is used verbatim for every panel.

'auto'
colors list

Explicit wedge colours, in the order the phenotypes appear.

None
autopct str

Percentage format string passed to Matplotlib, or None for no percentages.

'%1.1f%%'
legend bool

Draw a legend on each panel instead of relying on wedge labels.

False
legendLoc str

Matplotlib legend location.

'upper right'
wedgeprops dict

Passed through to Axes.pie, e.g. {"width": 0.4} for a donut.

None
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.

'pie.pdf'
saveDir str

Deprecated alias for outputDir, kept for scripts carried over from scimap. outputDir wins when both are given.

None
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.

300
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 group x phenotype count table with returnData=True; (fig, axes) with returnFig=True.

Example
# One pie per image.
sp.pl.pie(adata, phenotype="phenotype")

# Donut charts for two cell types across selected samples.
sp.pl.pie(
    adata,
    phenotype="phenotype",
    subsetPhenotype=["Treg", "NK cells"],
    subsetGroupBy=["sample_1", "sample_2"],
    wedgeprops={"width": 0.4},
    outputDir="figures",
    show=False,
)