Figures¶
kdb.pl draws the benchmark's figures with matplotlib. Each function returns its axes or figure.
These calls need only the kdomainbench package, not the method environments.
plot_k_estimates
¶
Plot the estimated k of each method against the reference domain number.
One row per method and one dot per estimate, laid out as Fig. 2b and 2c of the paper. A dashed line marks the reference domain number. A dot is blue when the method returned fewer domains than the reference, green when it returned as many, and red when it returned more. Methods are sorted by the median of their dots.
| PARAMETER | DESCRIPTION |
|---|---|
summary
|
The table from load_results.
TYPE:
|
ax
|
Axes to draw on. Default: a new figure.
TYPE:
|
k_reference
|
Reference domain number of every run, for a file without an annotation. Default: the
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The plot. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
KeyError
|
|
ValueError
|
|
Notes
- Runs of a method at the same place on the x axis share one dot, and its area gives their number.
- When the runs have different reference domain numbers (several datasets), the x axis is the k error, estimated k − reference k.
- Runs without a reference annotation are left out when other runs have one. When no run has one, the dots are gray and there is no line.
- The paper's panels also shade a dot by the size of its error. Here the position on the x axis gives the size, and the color only the direction.
Examples:
plot_metrics
¶
Plot the metrics of each method as a matrix of bars.
One row per method and one column per metric, laid out as Fig. 2f of the paper. The length of a bar is the value of the metric, on the metric's own axis below the column. The fill is the rank of the method among the methods for that metric: the darker, the better. The arrow above a column says whether higher or lower is better.
| PARAMETER | DESCRIPTION |
|---|---|
summary
|
The table from load_results. The columns of the twelve
metrics are there for the runs scored with metrics. A method
whose runs were not scored has
TYPE:
|
ax
|
Axes to draw on. Default: a new figure.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The plot. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
KeyError
|
|
ValueError
|
|
Notes
- With several runs per method, a bar is the mean over the runs that have a value, and
the whisker is their standard deviation. Filter
summaryfirst to compare within one dataset or device. In the paper the datasets of each data source are averaged first, and a bar is the mean over the five sources. - An axis runs from 0 to a round number above the highest value, and from below 0 when a value is negative. The axes of the paper's panel are set by hand and do not all start at 0.
- Methods are listed in the order of their first successful run in
summary. - Methods with the same value share the better rank.
n/amarks a metric without a value, such as SCS of a run with one domain.
Examples:
plot_runtime
¶
Plot run time or memory per method, CPU and GPU runs side by side.
| PARAMETER | DESCRIPTION |
|---|---|
summary
|
The table from load_results.
TYPE:
|
metric
|
TYPE:
|
ax
|
Axes to draw on. Default: a new figure.
TYPE:
|
log
|
Log-scale y axis.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The plot. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
|
KeyError
|
|
ValueError
|
|
Notes
- A bar is the mean over the runs of a method on one device (
device_used). A method without GPU code has only a CPU bar, also for runs made withdevice="gpu". - Methods are sorted by their mean over the devices, the smallest first.
Examples:
plot_spatial
¶
Plot the spatial domains of one run on the tissue.
| PARAMETER | DESCRIPTION |
|---|---|
clusters
|
Labels indexed by spot: what run returns, a Series, or a run folder.
TYPE:
|
h5ad
|
The input file or the data in memory. Its
TYPE:
|
ax
|
Axes to draw on. Default: a new figure.
TYPE:
|
title
|
Default
TYPE:
|
s
|
Marker size.
TYPE:
|
spatial_key
|
Key of the coordinates in
TYPE:
|
legend
|
Name the domains in a legend beside the map.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Axes
|
The map. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
The run folder or the |
KeyError
|
|
TypeError
|
|
ValueError
|
No label belongs to a spot of the file: the two do not use the same barcodes. |
Examples:
plot_spatial_grid
¶
Plot the spatial domains of several runs in a grid.
| PARAMETER | DESCRIPTION |
|---|---|
results
|
Name -> clusters or run folder, as run_all returns. For
finished runs:
TYPE:
|
h5ad
|
The input file or the data in memory.
TYPE:
|
ncols
|
Maps per row.
TYPE:
|
s
|
Marker size.
TYPE:
|
spatial_key
|
Key of the coordinates in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Figure
|
The grid. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
A run folder or the |
KeyError
|
|
TypeError
|
|
ValueError
|
|
Examples:
>>> results = kdb.run_all("data/D3_151509_5k.h5ad")
>>> kdb.pl.plot_spatial_grid(results, "data/D3_151509_5k.h5ad").savefig("domains.png")
For finished runs: