Skip to content

plot.plotting

Classes for storing plotting information.

The general workflow of generating plotting information is the following.

  1. Within simulation experiments abstract plotting information is stored. i.e., how from the data plots can be generated.

Working with multidimensional data ! Additional settings are required which allow to define how things are plotted. E.g. over which dimensions should an error be calculated and which dimensions should be plotted individually.

BasePlotObject

BasePlotObject(sid, name)

Base class for plotting objects.

Initialize BasePlotObject.

Parameters:

Name Type Description Default
sid str | None

Identifier of the object.

required
name str | None

Name of the object.

required

LineType

Bases: Enum

LineType options.

MarkerType

Bases: Enum

MarkerType options.

CurveType

Bases: Enum

CurveType options.

ColorType

ColorType(color)

ColorType class.

Encoding color information used in plots.

Initialize ColorType.

Parameters:

Name Type Description Default
color str

Color as hex string with alpha channel.

required

Raises:

Type Description
ValueError

If the color is None.

to_dict

to_dict()

Convert for serialization.

Returns:

Type Description
str

Color string.

parse_color staticmethod

parse_color(color, alpha=1.0)

Parse given color and add alpha information.

Parameters:

Name Type Description Default
color str | None

Color as matplotlib color string or hex color.

required
alpha float

Alpha value in [0, 1].

1.0

Returns:

Type Description
ColorType | None

ColorType or None if no color is given.

Raises:

Type Description
ValueError

If the hex color has an incorrect format.

Line dataclass

Line(type=SOLID, color=None, thickness=2.0)

Style of a line.

to_dict

to_dict()

Convert to dictionary for serialization.

Returns:

Type Description
dict[str, Any]

Dictionary of the line attributes.

Marker dataclass

Marker(
    size=6.0,
    type=NONE,
    fill=None,
    line_color=None,
    line_thickness=1.0,
)

Style of a marker.

to_dict

to_dict()

Convert to dictionary for serialization.

Returns:

Type Description
dict[str, Any]

Dictionary of the marker attributes.

Fill dataclass

Fill(color=None, second_color=None)

Style of a fill.

to_dict

to_dict()

Convert to dictionary for serialization.

Returns:

Type Description
dict[str, Any]

Dictionary of the fill attributes.

Style

Style(
    sid=None,
    name=None,
    base_style=None,
    line=None,
    marker=None,
    fill=None,
)

Bases: BasePlotObject

Style class.

Storing styling informatin about line, marker and fill. Styles can be derived from other styles based on the the base_style attribute.

Initialize Style.

Parameters:

Name Type Description Default
sid str | None

Identifier of the style.

None
name str | None

Name of the style.

None
base_style Style | None

Style this style is derived from.

None
line Line | None

Line style (default line if not provided).

None
marker Marker | None

Marker style (default marker if not provided).

None
fill Fill | None

Fill style.

None

to_dict

to_dict()

Serialize the declared style and its inheritance.

resolve_style

resolve_style()

Resolve all basestyle information.

Resolves the actual style information.

Returns:

Type Description
Style

Style with all information of the base styles applied.

to_mpl_curve_kwargs

to_mpl_curve_kwargs()

Convert to matplotlib curve keyword arguments.

Returns:

Type Description
dict[str, Any]

Keyword arguments for matplotlib curves.

to_mpl_points_kwargs

to_mpl_points_kwargs()

Convert to matplotlib point curve keyword arguments.

Returns:

Type Description
dict[str, Any]

Keyword arguments for matplotlib errorbar plots.

to_mpl_bar_kwargs

to_mpl_bar_kwargs()

Convert to matplotlib bar curve keyword arguments.

Returns:

Type Description
dict[str, Any]

Keyword arguments for matplotlib bar plots.

to_mpl_area_kwargs

to_mpl_area_kwargs()

Define keyword dictionary for a shaded area.

Returns:

Type Description
dict[str, Any]

Keyword arguments for matplotlib fill_between.

from_mpl_kwargs staticmethod

from_mpl_kwargs(**kwargs)

Create style from matplotlib arguments.

Parameters:

Name Type Description Default
**kwargs Any

Matplotlib styling arguments, e.g. color, alpha, linestyle, linewidth, marker, markersize, markerfacecolor, markeredgecolor, markeredgewidth.

{}

Returns:

Type Description
Style

Style corresponding to the matplotlib arguments.

AxisScale

Bases: Enum

Scale of the axis.

YAxisPosition

Bases: Enum

Position of yaxis.

Axis

Axis(
    label=None,
    unit=None,
    name=None,
    scale=LINEAR,
    min=None,
    max=None,
    reverse=False,
    grid=False,
    label_visible=True,
    ticks_visible=True,
    style=None,
)

Bases: BasePlotObject

Axis object.

Axis object.

The label and the unit form the axis label together, i.e. name is "<label> [<unit>]", and it follows both of them: setting label or unit on an axis updates it. name is the complete axis label and overrides them; setting it to None hands the axis back to its label and its unit.

Parameters:

Name Type Description Default
label str | None

label part of axis label

None
unit str | None

unit part of axis label

None
name str | None

complete axis label, overrides label and unit

None
scale AxisScale | str

Scale of the axis, i.e. "linear" or "log" axis.

LINEAR
min float | None

lower axis bound

None
max float | None

upper axis bound

None
reverse bool

flag to reverse axis plot order

False
grid bool

show grid lines along the axis

False
label_visible bool

show/hide the label text

True
ticks_visible bool

show/hide axis ticks

True
style Style | None

style of the axis

None

label property writable

label

Get the label part of the axis label.

unit property writable

unit

Get the unit part of the axis label.

name property writable

name

Get the complete axis label, which is what a figure renders.

The override if one was set, the label and the unit otherwise, so that a change of either of them is reflected.

scale property writable

scale

Get axis scale.

to_dict

to_dict()

Convert to dictionary.

Returns:

Type Description
dict[str, Any]

Dictionary of the axis attributes.

AbstractCurve

AbstractCurve(
    sid,
    name,
    x=None,
    order=None,
    style=None,
    yaxis_position=None,
)

Bases: BasePlotObject

Base class of Curves and ShadedAreas.

Abstract base class of Curve and ShadedArea.

Parameters:

Name Type Description Default
sid str | None

identifier of the curve

required
name str | None

label of the curve

required
x Data | None

x data

None
order int | None

order of the curve in the plot

None
style Style | None

style of the curve

None
yaxis_position YAxisPosition | None

position of the yaxis for the curve

None

Curve

Curve(
    x,
    y,
    sid=None,
    name=None,
    xerr=None,
    yerr=None,
    order=None,
    type=POINTS,
    style=None,
    yaxis_position=None,
    over=None,
    **kwargs,
)

Bases: AbstractCurve

Curve object.

Initialize Curve.

Parameters:

Name Type Description Default
x Data

x data

required
y Data

y data

required
sid str | None

identifier of the curve

None
name str | None

label of the curve (name of y data if not provided)

None
xerr Data | None

x error data

None
yerr Data | None

y error data

None
order int | None

order of the curve in the plot

None
type CurveType

type of the curve

POINTS
style Style | None

style of the curve (matplotlib kwargs are ignored if set)

None
yaxis_position YAxisPosition | None

position of the yaxis for the curve

None
over str | Sequence[str] | None

the dimensions of a scan with one line per point, see sbmlsim.plot.points

None
**kwargs Any

matplotlib styling arguments, label sets the name

{}

Raises:

Type Description
ValueError

if a dimension is named twice in over, or a curve which is not of points names one.

to_dict

to_dict()

Convert Curve to dictionary.

Returns:

Type Description
dict[str, Any]

Dictionary of the curve attributes.

ShadedArea

ShadedArea(
    x,
    yfrom,
    yto,
    order=None,
    style=None,
    yaxis_position=None,
    **kwargs,
)

Bases: AbstractCurve

ShadedArea class.

Initialize ShadedArea.

Parameters:

Name Type Description Default
x Data

x data

required
yfrom Data

lower y data

required
yto Data

upper y data

required
order int | None

order of the area in the plot

None
style Style | None

style of the area

None
yaxis_position YAxisPosition | None

position of the yaxis for the area

None
**kwargs Any

additional arguments, label, sid and name are used

{}

to_dict

to_dict()

Convert to dictionary.

Returns:

Type Description
dict[str, Any]

Dictionary of the area attributes.

Band

Band(
    x,
    y,
    across,
    quantiles=(0.05, 0.95),
    median=True,
    over=None,
    sid=None,
    name=None,
    color=None,
    alpha=0.3,
    order=None,
    yaxis_position=None,
)

Bases: AbstractCurve

The median and a quantile band of data over a dimension of draws.

The dimension across of y is reduced to the two quantiles, ignoring NaN, and the median, when the figure is drawn, see sbmlsim.plot.points.band_lines; over gives one band per point of other dimensions, in the colours of a curve over them.

Initialize a band.

Parameters:

Name Type Description Default
x Data

x data.

required
y Data

y data, with the dimension across.

required
across str

the dimension of the draws, which is reduced.

required
quantiles tuple[float, float]

the lower and the upper quantile, 0 <= low < high <= 1.

(0.05, 0.95)
median bool

draw the median as a line.

True
over str | Sequence[str] | None

the dimensions with one band per point.

None
sid str | None

identifier of the band.

None
name str | None

label of the band, the name of y by default.

None
color str | None

colour of the band; by default the colour of the colour cycle at the position of the band among the bands of its plot (C0, C1, ...).

None
alpha float

opacity of the area.

0.3
order int | None

order of the band in the plot.

None
yaxis_position YAxisPosition | None

position of the y axis of the band.

None

Raises:

Type Description
ValueError

if the quantiles are not increasing within [0, 1], across is in over, or over names more than one dimension.

to_dict

to_dict()

Convert the band to a dictionary.

Plot

Plot(
    sid,
    name=None,
    xaxis=None,
    yaxis=None,
    yaxis_right=None,
    curves=None,
    areas=None,
    bands=None,
    legend=True,
    facecolor=None,
    title_visible=True,
    height=None,
    width=None,
)

Bases: BasePlotObject

Plot panel.

A plot is the basic element of a plot. This corresponds to a single panel or axes combination in a plot. Multiple plots create a figure.

Initialize plot.

Parameters:

Name Type Description Default
sid str

Sid of the plot

required
name str | None

title of the plot

None
xaxis Axis | None

x-Axis

None
yaxis Axis | None

y-Axis

None
yaxis_right Axis | None

right y-Axis

None
curves list[Curve] | None

list of curves for the plots

None
areas list[ShadedArea] | None

list of shaded areas for the plots

None
bands list[Band] | None

list of bands for the plots

None
legend bool

boolean flag to show or hide legend

True
facecolor ColorType | None

color of the plot.

None
title_visible bool

boolean flag to show the title

True
height float | None

plot height (should be set on figure)

None
width float | None

plot width (should be set on figure)

None

Raises:

Type Description
ValueError

If the axes are not of type Axis.

figure property writable

figure

Get figure for plot.

Raises:

Type Description
ValueError

If the plot has no associated figure.

experiment property

experiment

Get simulation experiment for this plot.

title property writable

title

Get title.

xaxis property writable

xaxis

Get xaxis.

yaxis property writable

yaxis

Get yaxis.

yaxis_right property writable

yaxis_right

Get right yaxis.

curves property writable

curves

Get curves.

areas property writable

areas

Get areas.

bands property writable

bands

Get bands.

to_dict

to_dict()

Convert to dictionary.

Returns:

Type Description
dict[str, Any]

Dictionary of the plot attributes.

set_title

set_title(title)

Set title.

Parameters:

Name Type Description Default
title str

Title of the plot.

required

set_xaxis

set_xaxis(label, unit=None, **kwargs)

Set axis with all axes attributes.

All argument of Axis are supported.

Parameters:

Name Type Description Default
label str | Axis | None

label of Axis or Axis object

required
unit str | None

unit of the Axis (added to label)

None
**kwargs Any

additional Axis arguments

{}

set_yaxis

set_yaxis(label, unit=None, **kwargs)

Set axis with all axes attributes.

All argument of Axis are supported.

Parameters:

Name Type Description Default
label str | Axis | None

label of Axis or Axis object

required
unit str | None

unit of the Axis (added to label)

None
**kwargs Any

additional Axis arguments, e.g. label_visible

{}

set_yaxis_right

set_yaxis_right(label, unit=None, **kwargs)

Set axis with all axes attributes.

All argument of Axis are supported.

Parameters:

Name Type Description Default
label str | Axis | None

label of Axis or Axis object

required
unit str | None

unit of the Axis (added to label)

None
**kwargs Any

additional Axis arguments, e.g. label_visible

{}

add_curve

add_curve(curve)

Add Curve via the helper function.

All additions must go via this function to ensure data registration.

Parameters:

Name Type Description Default
curve Curve

Curve to add.

required

add_area

add_area(area)

Add ShadedArea via the helper function.

All additions must go via this function to ensure data registration.

Parameters:

Name Type Description Default
area ShadedArea

ShadedArea to add.

required

add_band

add_band(band)

Add a Band via the helper function.

Parameters:

Name Type Description Default
band Band

Band to add.

required

band

band(
    x,
    y,
    across,
    quantiles=(0.05, 0.95),
    median=True,
    over=None,
    name=None,
    color=None,
    alpha=0.3,
    yaxis_position=None,
    sid=None,
    order=None,
)

Create a band of the median and the quantiles of y over across and add it.

The arguments are those of Band.

Returns:

Type Description
Band

The band.

curve

curve(
    x,
    y,
    xerr=None,
    yerr=None,
    type=POINTS,
    style=None,
    yaxis_position=None,
    over=None,
    **kwargs,
)

Create curve and add to plot.

Parameters:

Name Type Description Default
x Data

x data

required
y Data

y data

required
xerr Data | None

x error data

None
yerr Data | None

y error data

None
type CurveType

type of curve (default points)

POINTS
style Style | None

style for curve

None
yaxis_position YAxisPosition | None

position of yaxis for this curve

None
over str | Sequence[str] | None

the dimensions of a scan with one line per point

None
**kwargs Any

matplotlib styling kwargs

{}

add_data

add_data(
    xid,
    yid,
    xid_sd=None,
    xid_se=None,
    yid_sd=None,
    yid_se=None,
    count=None,
    dataset=None,
    task=None,
    label="__yid__",
    type=POINTS,
    style=None,
    yaxis_position=None,
    sel=None,
    over=None,
    **kwargs,
)

Add a data curve to the plot.

Styling of curve is based on the provided style and matplotlib kwargs.

Parameters:

Name Type Description Default
xid str

index of x data

required
yid str

index of y data

required
xid_sd str | None

index of x SD data

None
xid_se str | None

index of x SE data

None
yid_sd str | None

index of y SD data

None
yid_se str | None

index of y SE data

None
count int | str | None

count for curve (number of subjects)

None
dataset str | None

dataset id

None
task str | None

task id

None
label str | None

label for curve (label=None for no label)

'__yid__'
type CurveType

type of curve (default points)

POINTS
style Style | None

style for curve

None
yaxis_position YAxisPosition | None

position of yaxis for this curve

None
sel Mapping[str, Any] | None

labels of the dimensions of a task, or column values of the rows of a dataset, for every Data of the curve, see Data

None
over str | Sequence[str] | None

the dimensions of a scan with one line per point

None
**kwargs Any

matplotlib styling kwargs

{}

Raises:

Type Description
ValueError

If the combination of arguments is not supported.

SubPlot

SubPlot(
    plot,
    row=None,
    col=None,
    row_span=1,
    col_span=1,
    sid=None,
    name=None,
)

Bases: BasePlotObject

A SubPlot holds a plot in a Figure.

The SubPlot defines the layout used by the plot, i.e., the position and number of panels the plot is spanning.

Initialize SubPlot.

Parameters:

Name Type Description Default
plot Plot

Plot of the subplot.

required
row int | None

row position of the plot in [1, num_rows]

None
col int | None

col position of the plot in [1, num_cols]

None
row_span int

number of rows the plot spans

1
col_span int

number of columns the plot spans

1
sid str | None

identifier of the subplot

None
name str | None

name of the subplot

None

to_dict

to_dict()

Serialize the plot and its position in the figure.

FigureSettings dataclass

FigureSettings(
    fig_dpi=72,
    fig_facecolor="white",
    fig_subplots_wspace=0.3,
    fig_subplots_hspace=0.3,
    panel_width=7.0,
    panel_height=5.0,
    fig_titlesize=25,
    fig_titleweight="bold",
    axes_titlesize=20,
    axes_titleweight="bold",
    axes_labelsize=18,
    axes_labelweight="bold",
    xtick_labelsize=15,
    ytick_labelsize=15,
    legend_fontsize=13,
    legend_position="inside",
    legend_loc="best",
    legend_scope="plot",
)

The settings a figure is rendered with.

The settings cascade, the more specific wins: the defaults of this class, the settings of the run (figure_settings= of SimulationExperiment.run, ExperimentRunner.run_experiments and the function run_experiments, a FigureSettings or a mapping of overrides of the defaults), the settings of the experiment (the class attribute SimulationExperiment.figure_settings, a mapping of overrides, which the subclasses of an experiment inherit) and the settings of the figure (Figure(settings=...), a mapping of overrides), see resolve. An override is a field by its name, e.g. {"fig_dpi": 300, "legend_fontsize": 10}. The settings of a figure therefore do not depend on the experiments which ran before it.

Attributes:

Name Type Description
fig_dpi float

the resolution of a static image in dots per inch, which turns the size of a figure in inches into its pixels. An interactive page has a fixed 72 pixels per inch, see serialization_plotly.PAGE_PIXELS_PER_INCH, whatever fig_dpi.

fig_facecolor str

the colour of the figure.

fig_subplots_wspace float

the horizontal spacing between the panels, as a fraction of the panel width.

fig_subplots_hspace float

the vertical spacing between the panels, as a fraction of the panel height.

panel_width float

the width of a panel in inches, which gives the width of a figure without an explicit width.

panel_height float

the height of a panel in inches, which gives the height of a figure without an explicit height.

fig_titlesize float

the font size of the title of the figure.

fig_titleweight str

the font weight of the title of the figure.

axes_titlesize float

the font size of the title of a plot.

axes_titleweight str

the font weight of the title of a plot.

axes_labelsize float

the font size of the label of an axis.

axes_labelweight str

the font weight of the label of an axis.

xtick_labelsize float

the font size of the tick labels of an x axis.

ytick_labelsize float

the font size of the tick labels of a y axis.

legend_fontsize float

the font size of a legend.

legend_position str

"inside" a plot or "outside" right of it.

legend_loc str

the location of a legend inside a plot, a location of matplotlib, e.g. "best" or "upper left".

legend_scope str

which plots a legend collects, LEGEND_SCOPES: "plot" a legend per plot, placed by legend_position and legend_loc; "row" one legend per row of the grid, right of the grid, with the entries of the plots of the row, an entry which reads and looks the same once (#327). The legend of a plot decides whether its entries enter the legend of its row.

names classmethod

names()

Get the names of the settings, in the order of the fields.

check classmethod

check(overrides, owner)

Check the overrides of a level of the cascade.

Parameters:

Name Type Description Default
overrides Mapping[str, Any] | None

the overrides by the names of the settings.

required
owner str

the level for the message, e.g. "the experiment 'Exp'".

required

Returns:

Type Description
dict[str, Any]

A copy of the overrides, empty for None.

Raises:

Type Description
TypeError

if the overrides are no mapping.

ValueError

if a key is no setting, the message names the settings.

resolve classmethod

resolve(run=None, experiment=None, figure=None)

Get the settings of the cascade, the more specific level wins.

Parameters:

Name Type Description Default
run FigureSettings | Mapping[str, Any] | None

the settings of the run, a FigureSettings or overrides of the defaults.

None
experiment Mapping[str, Any] | None

the overrides of the experiment, SimulationExperiment.figure_settings.

None
figure Mapping[str, Any] | None

the overrides of the figure, Figure.settings.

None

Returns:

Type Description
FigureSettings

The settings.

Raises:

Type Description
ValueError

if a level has a key which is no setting.

Figure

Figure(
    experiment,
    sid,
    name=None,
    subplots=None,
    height=None,
    width=None,
    num_rows=1,
    num_cols=1,
    settings=None,
)

Bases: BasePlotObject

A figure consists of multiple subplots.

A reference to the experiment is required, so the plot can resolve the datasets and the simulations. The figure is rendered with the settings of FigureSettings, which its settings override.

Initialize Figure.

Parameters:

Name Type Description Default
experiment SimulationExperiment | None

Simulation experiment the figure belongs to.

required
sid str

identifier of the figure

required
name str | None

title of the figure

None
subplots list[SubPlot] | None

subplots of the figure

None
height float | None

height of the figure in inches, without it the number of rows times the panel height of the settings it is rendered with

None
width float | None

width of the figure in inches, without it the number of columns times the panel width of the settings it is rendered with

None
num_rows int

number of panel rows

1
num_cols int

number of panel columns

1
settings Mapping[str, Any] | None

the settings of this figure, overrides of the settings of the run and of the experiment by name, e.g. {"legend_fontsize": 10}, see FigureSettings.

None

Raises:

Type Description
TypeError

if the settings are no mapping.

ValueError

if a key of the settings is no field of FigureSettings.

settings property writable

settings

Get the settings of this figure, overrides by name (read-only).

plots property

plots

Get plots in this figure.

resolved_settings

resolved_settings(experiment=None, run=None)

Get the settings the figure is rendered with.

The settings of the figure override those of its experiment, which override those of the run, see FigureSettings.resolve.

Parameters:

Name Type Description Default
experiment SimulationExperiment | None

the experiment the figure is rendered for, its figure_settings; without it there is no level of an experiment.

None
run FigureSettings | Mapping[str, Any] | None

the settings of the run, a FigureSettings or overrides of the defaults.

None

Returns:

Type Description
FigureSettings

The settings.

size

size(settings)

Get the width and the height in inches the figure is rendered with.

The explicit width and height, else the number of columns and rows times the panel size of the settings.

Parameters:

Name Type Description Default
settings FigureSettings

the settings the figure is rendered with, see resolved_settings.

required

Returns:

Type Description
tuple[float, float]

The width and the height.

num_panels

num_panels()

Get number of panel spots for plots.

Plots can span multiple of these panels.

Returns:

Type Description
int

Number of panels.

set_title

set_title(title)

Set title.

Parameters:

Name Type Description Default
title str | None

Title of the figure.

required

create_plots

create_plots(xaxis=None, yaxis=None, legend=True)

Create plots in the figure.

Settings are applied to all generated plots. E.g. if an xaxis is provided all plots have a copy of this xaxis.

Parameters:

Name Type Description Default
xaxis Axis | None

xaxis copied to all plots

None
yaxis Axis | None

yaxis copied to all plots

None
legend bool

flag to show legends

True

Returns:

Type Description
list[Plot]

Created plots.

get_plots

get_plots()

Get plots in this figure.

Returns:

Type Description
list[Plot]

Plots of all subplots.

add_subplot

add_subplot(plot, row, col, row_span=1, col_span=1)

Add plot as subplot to figure.

Be careful that individual subplots do not overlap when adding multiple subplots.

Parameters:

Name Type Description Default
plot Plot

Plot to add as subplot.

required
row int

row position for plot in [1, num_rows]

required
col int

col position for plot in [1, num_cols]

required
row_span int

span of figure with row + row_span <= num_rows

1
col_span int

span of figure with col + col_span <= num_cols

1

Returns:

Type Description
Plot

The added plot.

Raises:

Type Description
ValueError

If the position is outside of the figure.

add_plots

add_plots(plots, copy_plots=False)

Add plots to figure.

For every plot a subplot is generated.

Parameters:

Name Type Description Default
plots list[Plot]

Plots to add.

required
copy_plots bool

Flag to copy the plots before adding.

False

Raises:

Type Description
ValueError

If more plots than panels are provided.

to_dict

to_dict()

Convert to dictionary.

Returns:

Type Description
dict[str, Any]

Dictionary of the figure attributes.