Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Plot embeddings, markers, and distributions

Build the figures of a single-cell analysis with ds.plots: a UMAP colored by cell type and by gene, marker summaries across cell types, distributions within each type, the cell-type composition of computed clusters, and composed panels saved for a manuscript. The data are 3,696 cells of the embryonic mouse pancreas Bastidas-Ponce et al., 2019 in eight published cell types, from Ductal cells through Ngn3 low and Ngn3 high endocrine progenitors (EP) and Pre-endocrine cells to the hormone-producing Alpha, Beta, Delta, and Epsilon cells. The figures show the glucagon, insulin, and somatostatin genes each concentrated in its own endocrine type, where it is detected in 61% to 87% of the cells, and each hormone-producing type gathered in one computed cluster of the saved analysis.

Open the example data

The store holds a saved RNA analysis: a pipeline run labeled rna that records the cells, UMAP, and clusters that ds.pipeline.rna computed. ds.pipeline.open reopens the run without recomputing it, and run["umap"] returns its UMAP as an artifact reference, the handle that plots take as layout. The store’s cell metadata column clusters holds the published cell types, not the run’s computed clusters. A CellField points plots at a metadata column and gives it a label for legends, axes, and titles: “Cell type” for clusters, and “Counts per cell” and “Genes per cell” for each cell’s total counts and detected genes.

DataStore has 3696 (3696) cells with 1 assays: RNA Cell metadata: 'I', 'ids', 'names', 'G2M_score', 'RNA_UMAP1', 'RNA_UMAP2', 'RNA_clusters', 'RNA_leiden_cluster', 'RNA_nCounts', 'RNA_nFeatures', 'RNA_percentMito', 'RNA_percentRibo', 'S_score', 'clusters', 'clusters_coarse' RNA assay has 27998 features and following metadata: 'I', 'ids', 'names', 'dropOuts', 'highly_variable_genes', 'nCells'

Started: 2026-11-23T22:59:36.304279Z | Wall time: 7.279 s

Color an embedding

ds.plots.embedding draws the cells of a layout colored by what color_by names: a metadata column, a CellField, or a gene. A categorical column gives each category a color and a legend:

UMAP of the 3,696 pancreas cells colored by the eight published cell types, titled Cell type, with the legend on the right. Ductal cells mixed with Ngn3 low EP cells sit on the right, an arc of Ngn3 high EP cells crosses the top, Pre-endocrine cells fill the left, and Beta, Alpha, Delta, and Epsilon cells sit at the lower left.

Started: 2026-11-23T22:59:43.584737Z | Wall time: 0.199 s

The UMAP lays out the differentiation path: Ductal cells mixed with Ngn3 low EP cells on the right, an arc of Ngn3 high EP cells across the top, and Pre-endocrine cells on the left. The hormone-producing types sit at the lower left: Beta cells at the bottom, Alpha cells beside them, and the small Delta and Epsilon populations above the Alpha cells.

A gene name colors cells by the gene’s expression, and a list of genes draws one panel per gene. Expression is in counts per 1,000 counts of the cell, the scale that the RNA assay’s size factor ds.RNA.sf sets. Gcg, Ins2, and Sst encode glucagon, insulin, and somatostatin, the hormones of Alpha, Beta, and Delta cells:

Three UMAP panels colored by Gcg, Ins2, and Sst expression in counts per 1,000, each with its own color bar, which runs to about 125, 45, and 200. Gcg is high in the Alpha region, Ins2 at the lower tip of the Beta lobe, and Sst in the small Delta cluster, while all other cells are dark.

Started: 2026-11-23T22:59:43.784798Z | Wall time: 0.427 s

Each hormone marks the region of its cell type: Gcg the Alpha cells, Ins2 the lower tip of the Beta lobe, and Sst the Delta cluster. Each panel’s color scale runs to its brightest cells, so Beta cells with modest Ins2 look as dark as cells without it.

Make expression easier to see

Two display settings bring out cells near the bottom of a scale:

  • NormalizationSpec(transform="log1p") plots log(1 + x), which compresses the highest values.

  • ColorScale(quantiles=(0.0, 0.99)) ends the color range at the 99th percentile, so the top 1% of cells share the top color.

UMAP colored by log1p-transformed Ins2, with the color range capped at the 99th percentile, about 3.1. Ins2 rises along the Beta lobe at the lower left, from low values at its upper end next to the Pre-endocrine cells to the cap at its lower tip; the rest of the layout stays dark.

Started: 2026-11-23T22:59:44.213457Z | Wall time: 0.209 s

On the compressed and capped scale, Ins2 rises along the Beta lobe, from low values next to the Pre-endocrine cells to the cap at the lower tip. Both settings change only the colors, not the stored values, so state them in the figure legend when you publish.

Choose which cells are drawn on top

Where cells overlap, the cell drawn last hides the cells beneath it. Gene colors draw the highest values last, so a sparse marker stays visible above the cells that lack it. Cell types and other metadata columns draw in a random order fixed by seed (0 by default), so that the cells stored last, such as the last sample of a merged store, do not cover the others. seed=None keeps the stored order, and sort_values=True draws the highest values last for any continuous color.

To compare the two orders, the code below draws count depth, each cell’s total counts, into the two panels of one Matplotlib figure: target names the axis that each plot draws into, and show=False stops each call from displaying the figure before both panels are drawn:

Two UMAP panels colored by counts per cell on the same scale, from about 3,000 to 18,500. The left panel, titled Shuffled order (default), draws the cells in a random order; the right, titled Highest values last, draws the deepest cells on top, which makes the dense regions look deeper, most visibly the Ductal region at the lower right.

Started: 2026-11-23T22:59:44.423303Z | Wall time: 0.268 s

With the highest values last, the deepest cells cover their neighbors, so dense regions look deeper than most of their cells, most visibly the Ductal region on the right. In the shuffled order, the cell on top at each point is a random one, so the colors show the typical depth there.

Summarize markers across groups

A dot plot summarizes each gene in each group twice: color shows the mean expression, which counts cells without the gene as zeros, and dot size shows the fraction of cells whose expression exceeds expression_cutoff, zero by default. A large dark dot means widespread low expression; a small bright dot means strong expression in a few cells. The returned PlotResult keeps both values in tables["aggregate"]:

Dot plot of Gcg, Ins2, and Sst in rows across the eight cell types in columns, under the axis label clusters, the column's name. Color shows mean expression on one shared scale up to about 37, and dot size the fraction of cells in which the gene is detected. Large dots mark Gcg in Alpha, Ins2 in Beta, and Sst in Delta cells; Sst in Delta is the brightest, Gcg in Alpha is mid-scale, and Ins2 in Beta is dark, near the bottom of the scale. Gcg also shows smaller dark dots in every other type.
fractionmean per 1,000 counts
featureGcgIns2SstGcgIns2Sst
group
Alpha0.660.090.0323.170.030.01
Beta0.180.610.100.094.910.28
Delta0.170.090.870.030.0237.08
Ductal0.170.030.060.020.000.01
Epsilon0.340.040.021.970.010.03
Ngn3 high EP0.120.030.030.020.010.01
Ngn3 low EP0.180.030.060.020.000.01
Pre-endocrine0.120.040.040.030.010.08

Started: 2026-11-23T22:59:44.692567Z | Wall time: 0.261 s

Each hormone is detected in most cells of its own type, at a mean far above any other type: Gcg in 66% of Alpha cells at 23 counts per 1,000, Ins2 in 61% of Beta cells at 4.9, and Sst in 87% of Delta cells at 37. Gcg is also detected in 12% to 18% of the Ductal, EP, and Pre-endocrine cells, at means of 0.03 or less, and in 34% of Epsilon cells at 2.0, so its mean separates Alpha cells more sharply than its detected fraction does.

A matrix plot draws the means as a heatmap. In the dot plot, Sst in Delta cells set the top of the shared color scale and left Ins2 in Beta cells dark; standardize="feature" converts each gene’s means into z-scores across the cell types, so every gene spans the scale. categorical_scale adds the marker names to the labels of the hormone-producing types. A scale that sets only labels keeps the order and colors that the store records for the cell types, the order of the dot plot:

Heatmap of Gcg, Ins2, and Sst means standardized across the eight cell types, in the dot plot's order from Ductal to Epsilon, with Beta, Alpha, and Delta labeled by their marker genes. Each gene reaches the top of the scale only in its own cell type: Ins2 in Beta, Gcg in Alpha, and Sst in Delta. Gcg in Epsilon cells is the only other entry above the dark background.

Started: 2026-11-23T22:59:44.954600Z | Wall time: 0.263 s

On the standardized scale, Gcg in Alpha, Ins2 in Beta, and Sst in Delta cells all reach the top of the color range, and the only other entry above the dark background is Gcg in Epsilon cells. value="fraction" colors the matrix by detected fraction instead, and cluster_groups=True orders the groups by similarity under a dendrogram; the plotting API reference describes every option.

Inspect distributions

A mean hides how values spread within a group. Violins show the spread of count depth and detected genes in each cell type. max_points caps the cells drawn as points and max_density_points the values that estimate each violin, which keeps the plot fast on large datasets. The returned tables hold every cell’s value, for summaries such as medians:

Two rows of violins, titled Counts per cell and Genes per cell, across the eight cell types, with quartile lines and a sample of cells as points. Ductal cells have the highest medians, about 8,000 counts and 2,800 genes, and the longest upper tails, reaching about 18,500 counts and 4,500 genes; Pre-endocrine cells have the lowest medians.
('distribution', 'violin', 'subsampled_display', 'subsampled_density')
cellsmedian countsmedian genes
group
Alpha48155762343
Beta59161722528
Delta7056242257
Ductal91680442840
Epsilon14265222528
Ngn3 high EP64258992266
Ngn3 low EP26273602696
Pre-endocrine59248762170

Started: 2026-11-23T22:59:45.218918Z | Wall time: 0.224 s

Ductal cells have the deepest libraries, with medians of 8,044 counts and 2,840 genes and the longest upper tails, and Pre-endocrine cells the shallowest, at 4,876 counts and 2,170 genes. One threshold across the dataset would therefore remove more cells of some types than of others; Quality control and doublet detection shows how to check which populations a threshold removes.

The subsampled_display and subsampled_density notes flag that the figure was drawn from samples of the cells, and provenance.extras keeps the limits and the seed that drew them; the table’s medians use every cell. kind="box", kind="hist", and kind="ecdf" show the same values in other forms.

Stacked violins compare several genes across chosen groups: grouping names the labels that divide the cells, and groups keeps the listed ones:

Stacked violins of Gcg, Ins2, and Sst expression, one row per gene with its own value axis, in Alpha, Beta, and Delta cells. Each gene is high only in its own cell type: Gcg in Alpha cells piles up near zero with a tail to about 125, Ins2 in Beta cells piles up near zero with a tail to about 45, and Sst in Delta cells spreads up to about 200.

Started: 2026-11-23T22:59:45.443779Z | Wall time: 0.376 s

Gcg and Ins2 pile up near zero within their types, because they are detected in only 66% of Alpha cells and 61% of Beta cells, while Sst, detected in 87% of Delta cells, spreads over a wide range.

A violin of one gene across all eight cell types shows where else the gene is expressed:

Violins of Sst expression across the eight cell types. Delta cells spread from zero to about 200, Beta cells show a short tail up to about 20 and Pre-endocrine cells one up to about 11, and the other types stay near zero.

Started: 2026-11-23T22:59:45.821099Z | Wall time: 0.211 s

Outside the Delta cells, Beta cells have the longest Sst tail: Sst is detected in 10% of them, at a mean of 0.28 counts per 1,000.

Save a figure

The PlotResult that a plot returns writes the figure with save and releases its memory with close; with show=False, the figure is saved without being displayed:

{'file': 'figures/pancreas_cell_types.png', 'bytes': 181749}

Started: 2026-11-23T22:59:46.033044Z | Wall time: 0.112 s

The file extension sets the format, such as PNG, PDF, SVG, or TIFF, and dpi=300 sets the resolution of a raster format. exact_size=True, the default, keeps the figure’s size in inches, and exact_size=False crops it to its contents. provenance_sidecar=True also writes a JSON record of the plot’s cell count, scales, legends, and settings beside the file.

Focus on selected groups

facet_by splits the cells into one panel per group of a metadata column, and groups keeps the listed groups. The panels share one color scale, so their colors compare directly:

Three UMAP panels of Ins2 expression, titled Ins2 | clusters=Alpha, Beta, and Delta, on one shared color scale from 0 to about 45. Ins2 is bright only in the lower part of the Beta panel; the Alpha and Delta cells stay dark.

Started: 2026-11-23T22:59:46.145651Z | Wall time: 0.284 s

On the shared scale, the Alpha and Delta panels stay dark: Ins2 is detected in 9% of each, at means of 0.03 and 0.02.

A highlight draws one group in color over the faded other cells, which keeps the whole layout as context:

UMAP without a title, with the 591 Beta cells drawn in red over the other cells, which are faded to pale blue. The Beta cells fill the lobe at the lower left, up to its upper end next to the Pre-endocrine cells.

Started: 2026-11-23T22:59:46.430974Z | Wall time: 0.070 s

The 591 Beta cells fill the whole lobe, including its upper part next to the Pre-endocrine cells, where Ins2 is lowest within the lobe.

Compare composition across groups

ds.plots.composition stacks the fractions of each category within each group. Here the categories are the published cell types and the groups are the clusters that the saved run computed, passed as the run’s clusters artifact. Drawing into your own axis lets you name the axes and the legend:

Stacked bars for the 12 computed clusters of the saved run on the x axis, each split into the fractions of its cells in the eight published cell types, with a Cell type legend. Clusters 1, 3, 9, and 12 are mostly Beta, Alpha, Epsilon, and Delta cells, cluster 4 is entirely Ngn3 high EP, cluster 10 mixes Ngn3 high EP and Ngn3 low EP cells, clusters 2, 7, 8, and 11 are mostly Ductal, and clusters 5 and 6 mostly Pre-endocrine.

Started: 2026-11-23T22:59:46.502118Z | Wall time: 0.095 s

categoryproportionn_cells
cluster
1Beta0.97534
2Ductal0.77420
3Alpha0.94421
4Ngn3 high EP1.00385
5Pre-endocrine0.84310
6Pre-endocrine0.62215
7Ductal0.67153
8Ductal0.96205
9Epsilon0.70135
10Ngn3 high EP0.58102
11Ductal0.83120
12Delta0.7269

Started: 2026-11-23T22:59:46.598310Z | Wall time: 0.006 s

Each hormone-producing type gathers in one computed cluster: cluster 1 is 97% Beta and holds 534 of the 591 Beta cells, cluster 3 is 94% Alpha and holds 421 of the 481 Alpha cells, cluster 9 is 70% Epsilon and holds 135 of the 142 Epsilon cells, and cluster 12 is 72% Delta and holds 69 of the 70 Delta cells, with Pre-endocrine cells making up most of the rest of clusters 9 and 12. The other eight clusters are mostly Ductal, EP, and Pre-endocrine cells: Ductal cells make up most of clusters 2, 7, 8, and 11, Ngn3 high EP cells fill cluster 4 and make up most of cluster 10, and Pre-endocrine cells make up most of clusters 5 and 6.

With sample_by, the same plot draws one bar per sample instead. For matched donors, kind="per_sample" takes the StudyDesign that the donor-level comparisons tutorial builds and connects each donor’s proportions across conditions.

Compose panels and choose a style

A figure of your own can hold several CyteArc plots, here the cell types beside Ins2 expression:

Two UMAP panels in one figure, titled Cell types and Ins2: the cell types with their legend on the left, and Ins2 expression with a color bar from 0 to about 45 on the right. Ins2 is bright only at the lower tip of the Beta lobe.

Started: 2026-11-23T22:59:46.605136Z | Wall time: 0.309 s

cytearc.plotting.compose_results merges the results of such panels into one PlotResult, adds panel letters, and draws a legend that several panels share only once. Save a figure of your own with Matplotlib’s figure.savefig and close it with plt.close:

{'file': 'figures/pancreas_panels.pdf', 'bytes': 1296620}

Started: 2026-11-23T22:59:46.914715Z | Wall time: 1.255 s

theme="paper" uses smaller text for print, and theme="dark" draws light text and lines for dark notebook themes, on a transparent background that save fills with charcoal; the default is theme="notebook". By default, point size shrinks as the number of cells grows, and a plot with few categories, like these eight, gets a side legend. legend_loc="on_data" writes each category’s name on its cells instead:

UMAP colored by cell type, titled Cell type, with each of the eight names written on its population instead of in a legend. The Ngn3 low EP label sits among the Ductal cells on the right.

Started: 2026-11-23T22:59:48.170260Z | Wall time: 0.091 s

Names on the data suit a few separate populations. Where populations overlap, a name can land among another type’s cells, as Ngn3 low EP does among the Ductal cells.

Plot large datasets as pixels

embedding_raster averages a continuous metadata column, not a gene, over a grid of pixels. It reads the column in blocks rather than whole, so memory stays bounded, and it draws one value per pixel instead of overlapping points, for datasets too large to scatter quickly:

UMAP drawn as a grid of 60 by 60 pixels with axes labeled Embedding1 and Embedding2, each pixel colored by the mean counts per cell of the cells it holds, on a scale from about 3,500 to 14,300. The highest means lie along the lower edge of the Ductal region on the right, and the left side stays low.

Started: 2026-11-23T22:59:48.262072Z | Wall time: 0.079 s

The highest means lie along the lower edge of the Ductal region, where the Ductal cells with the deepest libraries sit, and the Pre-endocrine and endocrine regions on the left stay low.

Find the diagnostic plots

Diagnostic plots appear on the page of the analysis step they check:

References
  1. Bastidas-Ponce, A., Tritschler, S., Dony, L., Scheibner, K., Tarquis-Medina, M., Salinno, C., Schirge, S., Burtscher, I., Böttcher, A., Theis, F. J., Lickert, H., & Bakhti, M. (2019). Comprehensive single cell mRNA profiling reveals a detailed roadmap for pancreatic endocrinogenesis. Development, 146(12), dev173849. 10.1242/dev.173849