Skip to content

Figures (mtb.plot)

Draw figures from a long results table: mtb.load_results returns one for the stored results, mtb.evaluate and RunResult.long for your own runs.

Name Summary
mtb.plot.bubble Draw the paper's bubble table: methods as rows, metrics as columns.
mtb.plot.bar Draw each method's overall score as a horizontal bar, best on top.

mtb.plot.bubble

bubble(long_df, *, metrics=None, methods=None, title=None, save=None)

Draw the paper's bubble table: methods as rows, metrics as columns.

Metrics are grouped into families, each led by an Overall bar. Rows run best first, in the order of mtb.rank(category, long_df=long_df, metrics=...) with the same metrics.

PARAMETERS DESCRIPTION
long_df

A long table (method, metric, value and optional dataset), as mtb.load_results, mtb.evaluate and RunResult.long return; stored and your own rows can be concatenated.

type DataFrame

metrics

A family ("clustering", "batch", "classification", "all"), a code, or codes in their column order; None = every metric in the frame.

type str, list of str | None default None

methods

Methods (rows) to show; None = every method in the frame.

type list of str | None default None

title

Figure title; None = "<category> <dataset>" when the table holds one of each; "" = no title.

type str | None default None

save

File to write the figure to; the suffix picks the format (.pdf, .png, .svg).

type str or path - like | None default None

RETURNS DESCRIPTION
Figure
RAISES DESCRIPTION
ValueError

long_df lacks method / metric / value, repeats a (method, dataset, metric) row, holds your rows on another dataset than the stored rows, or metrics / methods names a value it does not hold.

WARNS DESCRIPTION
UserWarning

n/a cells, several datasets averaged per method, a column with the same value in every row, or a figure of one method.

Examples

>>> import multibench as mtb
>>> df = mtb.load_results("vertical", dataset="D11")
>>> fig = mtb.plot.bubble(df, metrics="clustering", save="d11.pdf")

mtb.plot.bar

bar(
    long_df: DataFrame,
    *,
    metrics=None,
    methods=None,
    title: str | None = None,
    save: str | None = None,
)

Draw each method's overall score as a horizontal bar, best on top.

Within each dataset the methods are ranked on each metric; the bar is the across-dataset score, in the order of mtb.rank(category, long_df=long_df, metrics=...) with the same metrics.

PARAMETERS DESCRIPTION
long_df

A long table (method, metric, value and optional dataset), as mtb.load_results, mtb.evaluate and RunResult.long return.

type DataFrame

metrics

A family ("clustering", "batch", "classification", "all") drawn in its colour, a code, or codes; None = every metric.

type str, list of str | None default None

methods

Methods (bars) to show, ranked among themselves; None = every method in the frame.

type list of str | None default None

title

Figure title; None = the dataset, or the number of datasets.

type str | None default None

save

File to write the figure to.

type str | None default None

RETURNS DESCRIPTION
Figure
RAISES DESCRIPTION
ValueError

long_df lacks method / metric / value, is empty, repeats a (method, dataset, metric) row, holds your rows on another dataset than the stored rows, or metrics / methods names a value it does not hold.

WARNS DESCRIPTION
UserWarning

A method missing from some datasets, a dataset with one method, a metric only one method has, or rows scored before 0.4.0.

Examples

>>> import multibench as mtb
>>> df = mtb.load_results("diagonal")
>>> fig = mtb.plot.bar(df, metrics="clustering", save="clustering.png")