plot.plotting¶
Classes for storing plotting information.
The general workflow of generating plotting information is the following.
- 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
¶
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 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. |
parse_color
staticmethod
¶
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
¶
Style of a line.
to_dict
¶
Convert to dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the line attributes. |
Marker
dataclass
¶
Style of a marker.
to_dict
¶
Convert to dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the marker attributes. |
Fill
dataclass
¶
Style of a fill.
to_dict
¶
Convert to dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the fill attributes. |
Style
¶
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
|
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
¶
Convert to matplotlib curve keyword arguments.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Keyword arguments for matplotlib curves. |
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
¶
Convert to matplotlib bar curve keyword arguments.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Keyword arguments for matplotlib bar plots. |
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
¶
Create style from matplotlib arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Matplotlib styling arguments, e.g. |
{}
|
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.
Label and unit form together the axis label. To set the label directly use the name attribute.
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 (overwrites 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
|
AbstractCurve
¶
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,
**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
|
**kwargs
|
Any
|
matplotlib styling arguments, |
{}
|
to_dict
¶
Convert Curve to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the curve attributes. |
ShadedArea
¶
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, |
{}
|
to_dict
¶
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the area attributes. |
Plot
¶
Plot(
sid,
name=None,
xaxis=None,
yaxis=None,
yaxis_right=None,
curves=None,
areas=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
|
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
¶
Get figure for plot.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the plot has no associated figure. |
to_dict
¶
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the plot attributes. |
set_title
¶
Set title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title of the plot. |
required |
set_xaxis
¶
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 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. |
{}
|
set_yaxis_right
¶
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. |
{}
|
add_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 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 |
curve
¶
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
|
**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,
**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
|
**kwargs
|
Any
|
matplotlib styling kwargs |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the combination of arguments is not supported. |
SubPlot
¶
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
|
Figure
¶
Figure(
experiment,
sid,
name=None,
subplots=None,
height=None,
width=None,
num_rows=1,
num_cols=1,
)
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.
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 (calculated from panels if not set) |
None
|
width
|
float | None
|
width of the figure (calculated from panels if not set) |
None
|
num_rows
|
int
|
number of panel rows |
1
|
num_cols
|
int
|
number of panel columns |
1
|
num_subplots
¶
Get number of subplots.
Returns:
| Type | Description |
|---|---|
int
|
Number of subplots. |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Title of the figure. |
required |
create_plots
¶
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
¶
add_subplot
¶
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 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. |
from_plots
staticmethod
¶
Create figure object from list of plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sid
|
str
|
identifier of the figure |
required |
plots
|
list[Plot]
|
plots stacked in a single column |
required |
experiment
|
SimulationExperiment
|
simulation experiment of the figure |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
Figure with the plots. |
to_dict
¶
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary of the figure attributes. |