Skip to content

Utils Module

datachart.utils

The module containing the utils.

The utils module provides a set of utilities used in the package.

MODULE DESCRIPTION
stats

The module containing the statistics functions.

FUNCTION DESCRIPTION
save_figure

Saves the figure into a file using the provided format parameters.

Functions

datachart.utils.save_figure

save_figure(
    figure: plt.Figure,
    path: str,
    dpi: int = 300,
    format: FIG_FORMAT = None,
    transparent: bool = False,
) -> None

Save the figure to a file.

Examples:

>>> # 1. create the figure
>>> from datachart.charts import LineChart
>>> figure = LineChart({...})
>>> # 2. save the figure
>>> from datachart.utils.figure import save_figure
>>> from datachart.constants import FIG_FORMAT
>>> path = "/path/to/save/chart.png"
>>> save_figure(figure, path, dpi=300, format=FIG_FORMAT.PNG, transparent=True)
PARAMETER DESCRIPTION
figure

The figure to save.

TYPE: plt.Figure

path

The path where the figure is saved.

TYPE: str

dpi

The DPI of the figure.

TYPE: int DEFAULT: 300

format

The format of the figure. If None, the format will be determined from the file extension.

TYPE: FIG_FORMAT DEFAULT: None

transparent

Whether to make the background transparent.

TYPE: bool DEFAULT: False