Matplotlib2DViewerTheme¶
Aliases:
petres.viewers.Viewer2DTheme
- class petres.viewers.Matplotlib2DViewerTheme[source]¶
Bases:
objectStore 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 bydataclassesbased on the declared fields. Runtime validation is performed in__post_init__.- __post_init__()[source]¶
Validate numeric theme values after dataclass initialization.
- Raises:
ValueError – If
marginsorgrid_linewidthis negative, ifgrid_alphais outside[0.0, 1.0], ifdpiis not strictly positive, or iftitle_fontsize/tick_labelsizeis 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)¶