pyfar.testing.plot_utils#

Functions for testing of plots.

Intended to reduce code redundancy and assure reproducibility on different operating systems. See the contribution guidelines.

Functions:

create_figure([width, height, dpi, style])

Create figure with defined parameters for reproducible testing.

save_and_compare(create_baseline, ...)

Save current Figure as Image and compare images against baseline.

pyfar.testing.plot_utils.create_figure(width=6, height=4.8, dpi=100, style='light')[source]#

Create figure with defined parameters for reproducible testing.

Parameters:
  • width (float) – The width in inch. The default is 6

  • height (float) – The height in inch. The default is 4.8

  • dpi (int) – The resolution in dots per inch. The default is 100

  • style (str) – light or dark to use the pyfar plot styles or a plot style from matplotlib.style.available. Pass a dictionary to set specific plot parameters, for example style = {'axes.facecolor':'black'}. Pass an empty dictionary style = {} to use the currently active plotstyle. The default is light.

Returns:

fig

Return type:

Matplotlib Figure object

pyfar.testing.plot_utils.save_and_compare(create_baseline, baseline_path, test_path, filename, file_type, compare_output)[source]#

Save current Figure as Image and compare images against baseline.

Parameters:
  • create_baseline (boolean) – If true, the current Figure is also used to create the baseline image against which everything is compared. This is usefull if the plot look changed.

  • baseline_path (str) – Folder where the baseline images are saved

  • test_path (str) – Folder where the images for testing against the baseline are saved

  • filename (str) – The name with which the image is saved

  • file_type (str) – The file type of the image file without the dot, e.g., 'png'

  • compare_output (boolen) – If false the saved images are compared against each other and a diff image is saved under test_oath in case they differ using matplotlib.testing.compare.compare_images. If true, an error is also raised if the images differ.