Plot base
puma.plot_base.PlotLineObject
dataclass
#
Base data class defining properties of a plot object.
Attributes:
| Name | Type | Description |
|---|---|---|
xmin |
(float | None, optional)
|
Minimum value of the x-axis, by default None |
xmax |
(float | None, optional)
|
Maximum value of the x-axis, by default None |
colour |
(str | None, optional)
|
Colour of the object, by default None |
label |
(str | None, optional)
|
Label of object, by default None |
linestyle |
(str | None, optional)
|
Linestyle following numpy style, by default None |
linewidth |
(float | None, optional)
|
Linewidth that will be used, by default None |
alpha |
(float | None, optional)
|
Value for visibility of the plot lines, by default None |
marker |
(str | None, optional)
|
Marker that is used in the plot. For example an x. By default None |
markersize |
(int | None, optional)
|
Size of the marker. By default None |
markeredgewidth |
(int | None, optional)
|
Edge width of the marker. By default None |
is_marker |
(bool | None, optional)
|
Bool, to give info about if this is a marker or a line. By default None |
args_to_store
property
#
Returns the arguments that need to be stored/loaded.
Returns:
| Type | Description |
|---|---|
dict[str, typing.Any]
|
Dict with the arguments |
decode
staticmethod
#
Inverse of encode, turning tags back into real objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
typing.Any
|
Object that is to be decoded |
required |
Returns:
| Type | Description |
|---|---|
typing.Any
|
The decoded object |
Source code in puma/plot_base.py
encode
staticmethod
#
Return a JSON/YAML-safe version of obj, tagging special types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
typing.Any
|
Object that is to be encoded |
required |
Returns:
| Type | Description |
|---|---|
typing.Any
|
The encoded object |
Source code in puma/plot_base.py
load
classmethod
#
Load attributes from file and construct the object without init.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | pathlib.Path
|
Path in which the attributes are stored. |
required |
**extra_kwargs
|
typing.Any
|
Extra kwargs to overwrite certain stored options. |
{}
|
Returns:
| Type | Description |
|---|---|
Class Instance
|
Instance of class with the given attributes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given file is neither json nor a yaml file. |
Source code in puma/plot_base.py
save
#
Store class attributes in a file (json or yaml).
Saving can be performed to a yaml and a json file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | pathlib.Path
|
Path to which the class object attributes are written. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown file extension was given |
Source code in puma/plot_base.py
puma.plot_base.PlotObject
dataclass
#
Data base class defining properties of a plot object.
Attributes:
| Name | Type | Description |
|---|---|---|
title |
(str, optional)
|
Title of the plot, by default "" |
draw_errors |
(bool, optional)
|
Draw statistical uncertainty on the lines, by default True |
xmin |
(float | None, optional)
|
Minimum value of the x-axis, by default None |
xmax |
(float | None, optional)
|
Maximum value of the x-axis, by default None |
ymin |
(float | None, optional)
|
Minimum value of the y-axis, by default None |
ymax |
(float | None, optional)
|
Maximum value of the y-axis, by default None |
ymin_ratio |
(list[float | None] | None, optional)
|
Set the lower y limit of each of the ratio subplots, by default None. |
ymax_ratio |
(list[float | None] | None, optional)
|
Set the upper y limit of each of the ratio subplots, by default None. |
y_scale |
(float, optional)
|
Scaling up the y axis, e.g. to fit the ATLAS Tag. Applied if ymax not defined, by default 1.3 |
logx |
(bool, optional)
|
Set the log of x-axis, by default False |
logy |
(bool, optional)
|
Set log of y-axis of main panel, by default True |
xlabel |
(str | None, optional)
|
Label of the x-axis, by default None |
ylabel |
(str | None, optional)
|
Label of the y-axis, by default None |
ylabel_ratio |
(list[str] | None, optional)
|
List of labels for the y-axis in the ratio plots, by default "Ratio" |
label_fontsize |
(int, optional)
|
Used fontsize in label, by default 12 |
fontsize |
(int, optional)
|
Used fontsize, by default 10 |
n_ratio_panels |
(int, optional)
|
Amount of ratio panels between 0 and 2, by default 0 |
vertical_split |
(bool, optional)
|
Set to False if you would like to split the figure horizontally. If set to True the figure is split vertically (e.g. for pie chart), by default False. |
figsize |
(tuple[float, float] | None, optional)
|
Tuple of figure size (width, height) in inches, by default None |
dpi |
(int, optional)
|
DPI used for plotting, by default 400 |
transparent |
(bool, optional)
|
Specify if the background of the plot should be transparent, by default False |
grid |
(bool, optional)
|
Set the grid for the plots, by default True. |
figure_layout |
(str, optional)
|
Set the layout that is used for the plot, by default "constrained" |
leg_fontsize |
(int | None, optional)
|
Fontsize of the legend, by default None (falls back to fontsize) |
leg_loc |
(str, optional)
|
Position of the legend in the plot, by default "upper right" |
leg_linestyle_loc |
(str, optional)
|
Position of the linestyle legend in the plot, by default "upper center" |
leg_ncol |
(int, optional)
|
Number of legend columns, by default 1 |
apply_atlas_style |
(bool, optional)
|
Apply ATLAS style for matplotlib, by default True |
use_atlas_tag |
(bool, optional)
|
Use the ATLAS Tag in the plots, by default True |
atlas_first_tag |
(str, optional)
|
First row of the ATLAS tag (i.e. "ATLAS |
atlas_second_tag |
(str | None, optional)
|
Second row of the ATLAS tag, by default None |
atlas_fontsize |
(int | None, optional)
|
Fontsize of ATLAS label, by default None (falls back to fontsize) |
atlas_vertical_offset |
(float, optional)
|
Vertical offset of the ATLAS tag, by default 7 |
atlas_horizontal_offset |
(float, optional)
|
Horizontal offset of the ATLAS tag, by default 8 |
atlas_brand |
(str | None, optional)
|
brand argument handed to atlasify. Use an empty string or None to remove it, by default "ATLAS" |
atlas_tag_outside |
(bool, optional)
|
outside argument handed to atlasify. Decides if the ATLAS logo is plotted outside of the plot (on top), by default False |
atlas_second_tag_distance |
(float, optional)
|
Distance between atlas_first_tag and atlas_second_tag in units of line spacing, by default 0 |
plotting_done |
(bool, optional)
|
Indicates if plotting is done. Only then atlasify() can be called, by default False |
__check_figsize
#
Check figsize is a tuple/list of length 2.
Raises:
| Type | Description |
|---|---|
ValueError
|
If shape of |
Source code in puma/plot_base.py
__check_yratio
#
Check yratio is a sequence of length n_ratio_panels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yratio
|
collections.abc.Sequence[float | None] | None
|
List of min or max limits of ratio plots |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in puma/plot_base.py
__post_init__
#
Check for allowed values.
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_ratio_panels not in [0, 1, 2, 3] |
Source code in puma/plot_base.py
puma.plot_base.PlotBase
#
Bases: puma.plot_base.PlotObject
Base class for plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
typing.Any
|
Keyword arguments from |
{}
|
Source code in puma/plot_base.py
atlasify
#
Apply ATLAS style to all axes using the atlasify package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
Force ATLAS style also if class variable is False, by default False |
False
|
Source code in puma/plot_base.py
close_window
#
Properly close the Tkinter window and exit the main loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
tkinter.Tk | None
|
The Tkinter root window instance to be closed. |
required |
Source code in puma/plot_base.py
draw_vlines
#
Draw vertical lines and optional labels on the axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xs
|
collections.abc.Sequence[float]
|
List of working points x values to draw |
required |
labels
|
collections.abc.Sequence[str | None] | None
|
List with labels for the vertical lines. Must be the same order as the xs. If None, the xvalues * 100 will be used as labels. By default None |
None
|
ys
|
collections.abc.Sequence[float] | None
|
List with the y height of the vertical lines in percent of the upper plot (0 is bottom, 1 is top). Must be the same order as the xs and the labels. By default None |
None
|
same_height
|
bool
|
Working point lines on same height, by default False |
False
|
colour
|
str
|
Colour of the vertical line, by default "#000000" (black) |
'#000000'
|
linestyle
|
str
|
Linestyle of the vertical line, by default "dashed" |
'dashed'
|
fontsize
|
int
|
Fontsize of the vertical line text. By default 10. |
10
|
Source code in puma/plot_base.py
initialise_figure
#
Create matplotlib Figure and subplots based on layout options.
Source code in puma/plot_base.py
is_running_in_jupyter
#
Detect if running inside a Jupyter notebook.
Returns:
| Type | Description |
|---|---|
bool
|
If the code is run inside a jupyter notebook |
Source code in puma/plot_base.py
make_legend
#
Draw legend on a given axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handles
|
list[matplotlib.lines.Line2D]
|
List of matplotlib.lines.Line2D object returned when plotting |
required |
ax_mpl
|
matplotlib.axes.Axes
|
|
required |
labels
|
list[str] | None
|
Plot labels. If None, the labels are extracted from the |
None
|
**kwargs
|
typing.Any
|
Keyword arguments which can be passed to matplotlib axis |
{}
|
Source code in puma/plot_base.py
make_linestyle_legend
#
Create a legend to indicate what different linestyles correspond to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linestyles
|
collections.abc.Sequence[str]
|
List of the linestyles to draw in the legend |
required |
labels
|
collections.abc.Sequence[str]
|
List of the corresponding labels. Has to be in the same order as the linestyles |
required |
loc
|
str | None
|
Location of the legend (matplotlib supported locations), by default None |
None
|
bbox_to_anchor
|
tuple[float, float] | tuple[float, float, float, float] | None
|
Allows to specify the precise position of this legend. Either a 2-tuple (x, y) or a 4-tuple (x, y, width, height), by default None |
None
|
axis_for_legend
|
matplotlib.axes.Axes | None
|
Axis on which to draw the legend, by default None |
None
|
Source code in puma/plot_base.py
savefig
#
Save plot to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot_name
|
str
|
File name of the plot |
required |
transparent
|
bool | None
|
Specify if plot background is transparent, by default False |
None
|
dpi
|
int | None
|
DPI for plotting, by default 400 |
None
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
set_log
#
Set log scale of axes as configured.
Source code in puma/plot_base.py
set_ratio_label
#
Associate the rejection class to a ratio panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ratio_panel
|
int
|
Index of the ratio panel to label. |
required |
label
|
str
|
y-axis label of the ratio panel. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the requested ratio panel does not exist. |
Source code in puma/plot_base.py
set_tick_params
#
Set tick params on all relevant axes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labelsize
|
int | None
|
Label size of x- and y- axis ticks, by default None. If None then using global fontsize |
None
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
set_title
#
Set title of top panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Title of top panel, if None using the value form the class variables, by default None |
None
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
set_xaxis_ticklabels_invisible
#
Helper function to set the ticklabels of the xaxis invisible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
matplotlib.axes.Axes
|
Axis you want to modify |
required |
Source code in puma/plot_base.py
set_xlabel
#
Set x-axis label on the bottom-most axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str | None
|
x-axis label, by default None |
None
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
set_xlim
#
Set limits of x-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
float | None
|
Min of x-axis, by default None |
None
|
xmax
|
float | None
|
Max of x-axis, by default None |
None
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
set_y_lim
#
Set limits of y-axis (main and ratios).
Source code in puma/plot_base.py
set_ylabel
#
Set y-axis label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax_mpl
|
matplotlib.axes.Axes
|
matplotlib axis object |
required |
label
|
str | None
|
x-axis label, by default None |
None
|
align
|
str | None
|
Alignment of y-axis label, by default "right" |
'right'
|
**kwargs
|
typing.Any
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
show
#
Show the plot using tkinter in CLI and detect Jupyter to avoid issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auto_close_after
|
int | None
|
After how many milliseconds, the window is automatically closed, by default None |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the figure is not initalized yet |