Matplotlib2DViewerTheme

Aliases:

  • petres.viewers.Viewer2DTheme


class petres.viewers.Matplotlib2DViewerTheme[source]

Bases: object

Store visual configuration for 2D Matplotlib viewers.

This dataclass centralizes figure, axes, grid, and typography defaults used by the 2D viewer layer. Values are intentionally conservative so they work well for both regular grids and irregular polygonal geometry.

Parameters:
  • figure_size (tuple[float, float], default=(9.0, 7.0)) – Figure size in inches as (width, height).

  • dpi (int, default=120) – Figure resolution in dots per inch.

  • constrained_layout (bool, default=True) – Whether Matplotlib constrained layout is enabled.

  • background (str | tuple[float, float, float] | tuple[float, float, float, float], default="white") – Axes background color accepted by Matplotlib.

  • aspect ({"auto", "equal"}, default="equal") – Aspect ratio mode passed to Matplotlib axes.

  • margins (float, default=0.03) – Relative axes margins. Must be non-negative.

  • grid (bool, default=True) – Whether to show major grid lines.

  • grid_alpha (float, default=0.18) – Grid line alpha in the inclusive range [0.0, 1.0].

  • grid_linestyle (str, default="--") – Matplotlib line style string for grid lines.

  • grid_linewidth (float, default=0.6) – Grid line width in points. Must be non-negative.

  • xlabel (str, default="X Axis") – X-axis label text.

  • ylabel (str, default="Y Axis") – Y-axis label text.

  • show_labels (bool, default=True) – Whether axis labels are rendered.

  • title_fontsize (float, default=13.0) – Font size used for plot titles. Must be positive.

  • hide_top_right_spines (bool, default=True) – Whether top and right spines are hidden.

  • tick_labelsize (float, default=10.0) – Font size used for tick labels. Must be positive.

Raises:

ValueError – If one or more numeric configuration fields are outside their valid ranges.

Examples

>>> theme = Matplotlib2DViewerTheme(background="whitesmoke", aspect="auto")
>>> theme.dpi
120

Notes

__init__ is generated by dataclasses based on the declared fields. Runtime validation is performed in __post_init__.

figure_size: tuple[float, float] = (9.0, 7.0)
dpi: int = 120
constrained_layout: bool = True
background: str | tuple[float, float, float] | tuple[float, float, float, float] = 'white'
aspect: Literal['auto', 'equal'] = 'equal'
margins: float = 0.03
grid: bool = False
grid_alpha: float = 0.18
grid_linestyle: str = '--'
grid_linewidth: float = 0.6
xlabel: str = 'X Axis'
ylabel: str = 'Y Axis'
show_labels: bool = True
title_fontsize: float = 13.0
hide_top_right_spines: bool = True
tick_labelsize: float = 10.0
__post_init__()[source]

Validate numeric theme values after dataclass initialization.

Raises:

ValueError – If margins or grid_linewidth is negative, if grid_alpha is outside [0.0, 1.0], if dpi is not strictly positive, or if title_fontsize / tick_labelsize is not strictly positive.

__init__(figure_size=(9.0, 7.0), dpi=120, constrained_layout=True, background='white', aspect='equal', margins=0.03, grid=False, grid_alpha=0.18, grid_linestyle='--', grid_linewidth=0.6, xlabel='X Axis', ylabel='Y Axis', show_labels=True, title_fontsize=13.0, hide_top_right_spines=True, tick_labelsize=10.0)