Source code for suboptimumg.plotting.plotting_constants
"""
Configuration objects for plotting module.
This module provides Plotly-style configuration objects to control various
aspects of plots without cluttering function interfaces. All magic numbers
are centralized here for easy customization.
"""
from typing import Dict, Optional
from pydantic import BaseModel, Field
# Hardcoded style constants to enforce consistency
TEXT_COLOR_DARK = "#303030" # For titles and axis labels
TEXT_COLOR_LIGHT = "#606060" # For subtitles
CONTOUR_LABEL_COLOR = "white" # Special case for contour labels on colored backgrounds
# Grid and zeroline styling (unified for all plot types)
GRID_WIDTH = 1
GRID_COLOR = "rgba(211, 211, 211, 1)"
ZEROLINE_WIDTH = 2
ZEROLINE_COLOR = "rgba(100, 100, 100, 0.7)"
# Float precision for all formatting (hover, ticks, labels, etc.)
FLOAT_PRECISION = ".2f"
# Hover mode
HOVER_MODE = "closest"
# Line styling
LINE_WIDTH = 2 # Standard line width for all plots
# Marker styling
MARKER_SIZE = 4 # Standard marker size for scatter plots
MARKER_SIZE_LARGE = 8 # Larger marker size for bar charts and emphasis
# Pad ranges
RANGE_PADDING = 0.05 # Expand the range by 5%
# Contour
NUM_CONTOURS = 10
# Bar chart styling
BAR_CHART_IMPLAUSIBLE_SYMBOL = "x" # Cross symbol for implausible points
BAR_CHART_XAXIS_TICKANGLE = 45 # Angle for rotated x-axis labels
[docs]
class FontConfig(BaseModel):
"""Font configuration for plot elements.
Simplified to three sizes that work across all plot types:
- Large: Titles
- Medium: Subtitles, axis labels, legend titles
- Small: Tick labels, legend items, contour labels
"""
large: int = 24 # Titles
medium: int = 16 # Subtitles, axis labels, legend titles
small: int = 12 # Tick labels, legend items, contour labels
[docs]
class LayoutConfig(BaseModel):
"""Layout configuration for plot dimensions and spacing.
Unified dimensions that work across all plot types. Users can override
when creating custom plots if needed.
"""
# Single width and height for all standard plots
width: int = 1000
height: int = 700
# Grid plot dimensions (when creating multi-subplot grids)
grid_width_per_col: int = 400
grid_height_per_row: int = 350
grid_horizontal_spacing: float = 0.08
grid_vertical_spacing: float = 0.12
# Single margin configuration (left, right, top, bottom)
margin: Dict[str, int] = Field(default_factory=lambda: dict(l=70, r=50, t=90, b=70))
# Background colors
plot_bgcolor: str = "white"
scene_bgcolor: str = "rgba(240, 240, 240, 0.8)"
# Title positioning
title_x: float = 0.5
title_xanchor: str = "center"
title_yanchor: str = "top"
[docs]
class ColorbarConfig(BaseModel):
"""Colorbar configuration for 3D plots."""
thickness: int = 15
length: float = 0.7
[docs]
class SmoothingConfig(BaseModel):
"""Smoothing and interpolation configuration."""
interp_factor: int = 5 # Multiplier for grid density
smoothing_sigma: float = 0 # Gaussian smoothing sigma, 0 = no smoothing
interp_method: str = "linear"
[docs]
class SceneConfig(BaseModel):
"""3D scene configuration for surface plots."""
# Aspect ratio (x, y, z)
aspect_ratio_x: float = 1.0
aspect_ratio_y: float = 1.0
aspect_ratio_z: float = 0.8
# Camera position
camera_distance: float = 2.0
camera_z: float = 0.8
default_view_angle: int = -60 # degrees
# Camera up vector
camera_up_x: float = 0
camera_up_y: float = 0
camera_up_z: float = 1
[docs]
class ReferenceLineConfig(BaseModel):
"""Configuration for reference lines (h_line, v_line).
This class combines the line value, label, and styling into a single object.
Pass instances of this class to plotting functions instead of separate parameters.
"""
# Line value and label
value: Optional[float] = None # Numeric position of the line (None = no line)
label: Optional[str] = None # Label for the line in legend
# Reference line styling
width: int = 4
dash: str = "dash"
color: str = "red"
# Default configuration instances
DEFAULT_FONT_CONFIG = FontConfig()
DEFAULT_LAYOUT_CONFIG = LayoutConfig()
DEFAULT_COLORBAR_CONFIG = ColorbarConfig()
DEFAULT_SMOOTHING_CONFIG = SmoothingConfig()
DEFAULT_SCENE_CONFIG = SceneConfig()