Graphic functions#

barotropy.graphics.create_gif(image_folder, output_file, duration=0.5)[source]#

Create a GIF from a series of images.

Parameters:
image_folderstr

The path to the folder containing the images.

output_filestr

The path and filename of the output GIF.

durationfloat, optional

Duration of each frame in the GIF, by default 0.5 seconds.

barotropy.graphics.create_mp4(image_folder, output_file, fps=10)[source]#

Create an MP4 video from a series of images.

Parameters:
image_folderstr

The path to the folder containing the images.

output_filestr

The path and filename of the output MP4 video.

fpsint, optional

Frames per second in the output video, by default 10.

barotropy.graphics.plot_xy_data(data, figs_axes, settings, figsize=(6.0, 5.0), label=None, color=None)[source]#

Plots data and manages figure and axes creation.

Note

This function creates new figures and axes only if they do not already exist, ensuring idempotent behavior over multiple calls.

Parameters:
datadict

Dictionary containing multiple arrays with data to be plotted. Keys correspond to variable names, and values are arrays of data points. All arrays should be of the same size.

figs_axesdict

Dictionary to store figures and axes. The key is a tuple of (var_x, var_y) and the value is a tuple of (fig, ax).

settingsdict

Dictionary containing plot settings, including:

  • var_x (str): Name of the x variable.

  • var_y (str): Name of the y variable.

  • xlabel (str): Label for the x-axis.

  • ylabel (str): Label for the y-axis.

  • x_scale (str): Scale for the x-axis (e.g., “linear”, “log”). Default is “linear”.

  • y_scale (str): Scale for the y-axis (e.g., “linear”, “log”). Default is “linear”.

  • x_lim (list or tuple): Limits for the x-axis (min, max).

  • y_lim (list or tuple): Limits for the y-axis (min, max).

figsizetuple, optional

Size of the figure, by default (6.0, 5.0).

labelstr, optional

Label for the plot line, by default None. If None, no label is added.

colorstr, optional

Color for the plot line, by default None. If None, the default color cycle is used.

Returns:
figs_axesdict

Updated dictionary containing figures and axes.

Examples

>>> figs_axes = {}
>>> plot_settings = {
...     "var_x": "p",
...     "var_y": "density",
...     "xlabel": "Pressure (bar)",
...     "ylabel": "Density (kg/m$^3$)",
...     "x_scale": "linear",
...     "y_scale": "log",
...     "x_lim": [None, None],
...     "y_lim": [1, 1000]
... }
>>> data = {
...     "p": [1, 2, 3, 4],
...     "density": [10, 100, 1000, 10000],
...     "T": [300, 310, 320, 330]
... }
>>> figs_axes = plot_xy_data(data, figs_axes, plot_settings, label="Sample Data")
barotropy.graphics.print_installed_fonts()[source]#

Print the list of fonts installed on the system.

This function identifies and prints all available fonts for use in Matplotlib.

barotropy.graphics.print_rc_parameters(filename=None)[source]#

Print the current rcParams used by Matplotlib or write to file if provided.

This function provides a quick overview of the active configuration parameters within Matplotlib.

barotropy.graphics.savefig_in_formats(fig, path_without_extension, formats=['.png', '.svg', '.eps'], dpi=500)[source]#

Save a given Matplotlib figure in multiple file formats.

Parameters:
figmatplotlib.figure.Figure

The figure object to be saved.

path_without_extensionstr

The full path to save the figure excluding the file extension.

formatslist of str, optional

A list of string file extensions to specify which formats the figure should be saved in. Supported formats are [‘.png’, ‘.svg’, ‘.pdf’, ‘.eps’]. Default is [‘.png’, ‘.svg’].

dpiint, optional

The resolution in dots per inch with which to save the image. This parameter affects only PNG files. Default is 500.

Examples

>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot([0, 1], [0, 1])
>>> save_fig_in_formats(fig, "/path/to/figure/filename")

This will save the figure as “filename.png”, “filename.svg”, and “filename.pdf” in the “/path/to/figure/” directory.

barotropy.graphics.scale_graphics_x(fig, scale, mode='multiply')[source]#

Scale x-coordinates of graphics objects

barotropy.graphics.scale_graphics_y(fig, scale, mode='multiply')[source]#

Scale y-coordinates of graphics objects

barotropy.graphics.set_plot_options(fontsize=14, grid=True, major_ticks=True, minor_ticks=True, margin=0.05, color_order='matlab', linewidth=1.25)[source]#

Set options for creating publication-quality figures using Matplotlib.

This function updates the internal Matplotlib settings to better align with standards for publication-quality figures. Features include improved font selections, tick marks, grid appearance, and color selections.

Parameters:
fontsizeint, optional

Font size for text elements in the plot. Default is 13.

gridbool, optional

Whether to show grid lines on the plot. Default is True.

major_ticksbool, optional

Whether to show major ticks. Default is True.

minor_ticksbool, optional

Whether to show minor ticks. Default is True.

marginfloat, optional

Margin size for axes. Default is 0.05.

color_orderstr, optional

Color order to be used for plot lines. Options include “python” and “matlab”. Default is “matlab”.