Common features

The different plot classes share a large number of features and properties that are inherited from the same base plot class and are presented in the following sections.

Automatic axis settings

Most of the plot classes will try to set correct axis labels based on the input data set automatically if the x- or y-label properties are None. This feature is convenient in most cases and it helps to produce appropriate plots out-of-the-box, however, sometimes the user may want to manually set the axis properties. This can be accomplished by switching off this feature via the auto_set_axis_properties function (here examplified using the BandStructurePlot class):

[1]:
from aim2dat.io.cp2k import read_band_structure
from aim2dat.plots import BandStructurePlot

plot = BandStructurePlot()
plot.ratio = (7, 3)
plot.y_range = [-10, 10]
plot.import_band_structure(
    "test",
    **read_band_structure("../../example_notebooks/files/el_bands_cp2k/bands.bs"),
)
plot.plot("test")
[1]:
_images/plots-properties_and_functions_1_0.png

The y-label is set to the default label which is 'Energy in eV' for the band structure plot. The default label can be overwritten by setting the property y_label or via the auto_set_axis_properties function:

[2]:
plot.y_label = "new label"
plot.plot("test")
[2]:
_images/plots-properties_and_functions_3_0.png
[3]:
plot.y_label = None
plot.auto_set_axis_properties(set_x_label=False, set_y_label=False)
plot.plot("test")
[3]:
_images/plots-properties_and_functions_4_0.png

Plot customizations

A manifold of settings can be changed for the matplotlib backend by writing a customized style sheet (a detailed description is given in the matplotlib documentation) and setting the path to the file via the style_sheet property. The default style sheet file can be found in aim2dat/plots/matplotlib_style_sheets/custom_settings.mplstyle.

Additionally, there are bunch of custom_* properties that change certain aspects of the plots. It needs to be noted that at the moment not all plots support all of those properties. We examplify a few of these properties once again using the BandStructurePlot class. The properties custom_colors, custom_linestyles, custom_linewidths, custom_markers and custom_alpha expect a list as input. Each list item usually applies to the elements of the specific data set in the same order as the data_labels are given in the plot function:

[4]:
plot.custom_colors = ["orange"]
plot.custom_linewidths = [2]
plot.custom_linestyles = [":"]

The properties custom_xticks and custom_yticks expect a list of float numbers or a nested list in case of several subplots; the properties custom_xticklabels and custom_yticklabels expect a list or nested list of strings:

[5]:
plot.custom_xticks = [0, 1.2, 2.0, 5.0]
plot.custom_xticklabels = ["T", "E", "S", "T"]
plot.custom_yticks = [-10.0, -7.5, -5.0, -2.5, 0.0, 2.5, 5.0, 7.5, 10.0]
plot.plot("test")
[5]:
_images/plots-properties_and_functions_8_0.png

Supported plot backends

So far we have only used the default backend library to create the plots, namely the popular matplotlib package. In order to analyse data sets in an interactive way the plotly package is supported as second backend. The backend can be readily changed via the backend property:

[6]:
import plotly.io as pio
pio.renderers.default = "sphinx_gallery"

plot.ratio = (6.3, 6.3)
plot.backend = "plotly"
plot.plot("test")

List of all class properties

Note

Links to properties and functions are given for the SimplePlot class but are available for all other plot classes as well.

The following properties are implemented for each class, quite a few of the property names are based on the matplotlib user interface:

General properties

Property

Description

data_labels

List of all data labels.

backend

The backend library used to create the plot.

style_sheet

Custom matplotlib stylesheet.

ratio

Width-height ratio of the plot.

equal_aspect_ratio

Whether the plot should have equal aspect ratio.

store_path

Path where the plot is stored.

store_plot

Whether to store the plot or not.

show_plot

Whether to show the plot.

show_legend

Whether to show the legend in the plot.

show_grid

Whether to show a grid in the plot.

x_label

Label of the x-axis.

y_label

Label of the y-axis.

x_range

Range of the x-axis.

y_range

Range of the y-axis.

Property

Description

legend_loc

Location of the legend in the plot.

legend_bbox_to_anchor

Shift between box and anchor.

legend_ncol

Columns of the legend.

legend_sort_entries

Sort entries of the legend.

Property

Description

custom_colors

Colors used in the plot.

custom_linestyles

Line styles used in the plot.

custom_linewidths

Line widths used in the plot.

custom_markers

Marker types used in the plot.

custom_alpha

Alpha values controlling the opacity of plot elements.

custom_xticks

List of values to set ticks on the x-axis.

custom_yticks

List of values to set ticks on the y-axis.

custom_xticklabels

List of labels for the ticks on the x-axis.

custom_yticklabels

List of labels for the ticks on the y-axis.

Property

Description

subplot_sup_title

Title of the whole figure.

subplot_sup_x_label

x-label of the whole figure.

subplot_sup_y_label

y-label of the whole figure.

subplot_nrows

Number of rows.

subplot_ncols

Number of columns.

subplot_gridspec

Grid spec values.

subplot_hspace

Vertical spacing between the subplots.

subplot_wspace

Horizontal spacing between the subplots.

subplot_adjust

Keyword arguments for the matplotlib subplots_adjust function.

subplot_share_legend

Merge legend items of all subplots.

subplot_share_colorbar

Use one common colorbar for all subplots.

subplot_sharex

Share the x-axis of subplots located in the same column.

subplot_sharey

Share the y-axis of subplots located in the same row.

subplot_tight_layout

Whether to use tight layout of the plot.