Skip to content

chemdiagrams.managers.figure_manager

FigureManager

Creates and owns the Matplotlib figure and axes used by the diagram.

Acts as the central reference point for all other managers, which access the figure and axes through this object rather than holding their own references.

Source code in src/chemdiagrams/managers/figure_manager.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class FigureManager:
    """
    Creates and owns the Matplotlib figure and axes used by the diagram.

    Acts as the central reference point for all other managers, which
    access the figure and axes through this object rather than holding
    their own references.
    """

    def __init__(
        self,
        fontsize: int = constants.STD_FONTSIZE,
        dpi: int = 150,
    ) -> None:
        """
        Initialize the Matplotlib figure and configure default tick styling.

        Parameters
        ----------
        fontsize : int, optional
            Base font size applied to axis tick labels throughout the diagram.
            Default is ``constants.STD_FONTSIZE``.
        dpi : int, optional
            Resolution of the figure in dots per inch. Default is 150.
        """

        # Sanity checks
        Validators.validate_number(fontsize, "fontsize", min_value=0)
        Validators.validate_number(dpi, "dpi", min_value=0)

        # Initialize the diagram, get the axis and set axis limits
        self.fig = plt.figure(dpi=dpi)
        self.ax = self.fig.gca()
        self.ax.tick_params(
            which="both", direction="inout", top=False, right=False, bottom=False
        )
        self.ax.tick_params(which="both", labelsize=fontsize)
        self.ax.set_xticks([])
        self.fontsize = fontsize

__init__(fontsize=constants.STD_FONTSIZE, dpi=150)

Initialize the Matplotlib figure and configure default tick styling.

Parameters:

Name Type Description Default
fontsize int

Base font size applied to axis tick labels throughout the diagram. Default is constants.STD_FONTSIZE.

STD_FONTSIZE
dpi int

Resolution of the figure in dots per inch. Default is 150.

150
Source code in src/chemdiagrams/managers/figure_manager.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(
    self,
    fontsize: int = constants.STD_FONTSIZE,
    dpi: int = 150,
) -> None:
    """
    Initialize the Matplotlib figure and configure default tick styling.

    Parameters
    ----------
    fontsize : int, optional
        Base font size applied to axis tick labels throughout the diagram.
        Default is ``constants.STD_FONTSIZE``.
    dpi : int, optional
        Resolution of the figure in dots per inch. Default is 150.
    """

    # Sanity checks
    Validators.validate_number(fontsize, "fontsize", min_value=0)
    Validators.validate_number(dpi, "dpi", min_value=0)

    # Initialize the diagram, get the axis and set axis limits
    self.fig = plt.figure(dpi=dpi)
    self.ax = self.fig.gca()
    self.ax.tick_params(
        which="both", direction="inout", top=False, right=False, bottom=False
    )
    self.ax.tick_params(which="both", labelsize=fontsize)
    self.ax.set_xticks([])
    self.fontsize = fontsize