ergodic_insurance.visualization_infra package
Submodules
ergodic_insurance.visualization_infra.figure_factory module
Figure factory for creating standardized plots with consistent styling.
This module provides a factory class for creating various types of plots with automatic styling, spacing, and formatting applied consistently.
- class FigureFactory(style_manager: StyleManager | None = None, theme: Theme = Theme.DEFAULT, auto_apply: bool = True)[source]
Bases:
objectFactory for creating standardized figures with consistent styling.
This class provides methods to create various types of plots with automatic application of themes, consistent formatting, and proper spacing.
Example
>>> factory = FigureFactory(theme=Theme.PRESENTATION) >>> fig, ax = factory.create_line_plot( ... x_data=[1, 2, 3, 4], ... y_data=[10, 20, 15, 25], ... title="Revenue Growth", ... x_label="Quarter", ... y_label="Revenue ($M)" ... )
>>> # Create multiple subplots >>> fig, axes = factory.create_subplots( ... rows=2, cols=2, ... size_type="large", ... subplot_titles=["Q1", "Q2", "Q3", "Q4"] ... )
- create_figure(size_type: str = 'medium', orientation: str = 'landscape', dpi_type: str = 'screen', title: str | None = None) Tuple[Figure, Axes][source]
Create a basic figure with styling applied.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes)
- create_subplots(rows: int = 1, cols: int = 1, size_type: str = 'large', dpi_type: str = 'screen', title: str | None = None, subplot_titles: List[str] | None = None, **kwargs) Tuple[Figure, Axes | ndarray][source]
Create subplots with consistent styling.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes array)
- create_line_plot(x_data: List | ndarray | Series, y_data: List | ndarray | Series | Dict[str, List | ndarray], title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', show_legend: bool = True, show_grid: bool = True, markers: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a line plot with automatic formatting.
- Parameters:
y_data (
Union[List,ndarray,Series,Dict[str,Union[List,ndarray]]]) – Y-axis data (can be multiple series as dict)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeshow_legend (
bool) – Whether to show legendshow_grid (
bool) – Whether to show gridmarkers (
bool) – Whether to add markers to lines**kwargs – Additional arguments for plot
- Return type:
- Returns:
Tuple of (figure, axes)
- create_bar_plot(categories: List | ndarray, values: List | ndarray | Dict[str, List | ndarray], title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', orientation: str = 'vertical', show_values: bool = False, value_format: str = '.1f', **kwargs) Tuple[Figure, Axes][source]
Create a bar plot with automatic formatting.
- Parameters:
values (
Union[List,ndarray,Dict[str,Union[List,ndarray]]]) – Values to plot (can be multiple series as dict)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeorientation (
str) – Bar orientation (vertical or horizontal)show_values (
bool) – Whether to show value labels on barsvalue_format (
str) – Format string for value labels**kwargs – Additional arguments for bar plot
- Return type:
- Returns:
Tuple of (figure, axes)
- create_scatter_plot(x_data: List | ndarray, y_data: List | ndarray, title: str | None = None, x_label: str | None = None, y_label: str | None = None, size_type: str = 'medium', dpi_type: str = 'screen', colors: List | ndarray | None = None, sizes: List | ndarray | None = None, labels: List[str] | None = None, show_colorbar: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a scatter plot with automatic formatting.
- Parameters:
size_type (
str) – Figure size presetdpi_type (
str) – DPI typecolors (
Union[List,ndarray,None]) – Optional colors for points (for continuous coloring)sizes (
Union[List,ndarray,None]) – Optional sizes for pointsshow_colorbar (
bool) – Whether to show colorbar when colors provided**kwargs – Additional arguments for scatter
- Return type:
- Returns:
Tuple of (figure, axes)
- create_histogram(data: List | ndarray | Series, title: str | None = None, x_label: str | None = None, y_label: str = 'Frequency', bins: int | str = 'auto', size_type: str = 'medium', dpi_type: str = 'screen', show_statistics: bool = False, show_kde: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a histogram with automatic formatting.
- create_heatmap(data: ndarray | DataFrame, title: str | None = None, x_labels: List[str] | None = None, y_labels: List[str] | None = None, x_label: str | None = None, y_label: str | None = None, size_type: str = 'medium', dpi_type: str = 'screen', cmap: str = 'RdBu_r', show_values: bool = True, value_format: str = '.2f', **kwargs) Tuple[Figure, Axes][source]
Create a heatmap with automatic formatting.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes)
- create_box_plot(data: List[List] | Dict[str, List] | DataFrame, title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', orientation: str = 'vertical', show_means: bool = True, **kwargs) Tuple[Figure, Axes][source]
Create a box plot with automatic formatting.
- Parameters:
data (
Union[List[List],Dict[str,List],DataFrame]) – Data for box plot (list of lists, dict, or DataFrame)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeorientation (
str) – Plot orientation (vertical or horizontal)show_means (
bool) – Whether to show mean markers**kwargs – Additional arguments for boxplot
- Return type:
- Returns:
Tuple of (figure, axes)
- format_axis_currency(ax: Axes, axis: str = 'y', abbreviate: bool = True, decimals: int = 0) None[source]
Format axis labels as currency.
- format_axis_percentage(ax: Axes, axis: str = 'y', decimals: int = 0) None[source]
Format axis labels as percentages.
- add_annotations(ax: Axes, x: float, y: float, text: str, arrow: bool = True, offset: Tuple[float, float] = (10, 10), **kwargs) None[source]
Add styled annotation to plot.
ergodic_insurance.visualization_infra.style_manager module
Style management for consistent visualization across all reports.
This module provides centralized style configuration for all visualizations, including color palettes, fonts, figure sizes, and DPI settings.
- class Theme(*values)[source]
Bases:
EnumAvailable visualization themes.
- DEFAULT = 'default'
- COLORBLIND = 'colorblind'
- PRESENTATION = 'presentation'
- MINIMAL = 'minimal'
- PRINT = 'print'
- class ColorPalette(primary: str = '#0080C7', secondary: str = '#003F5C', accent: str = '#FF9800', warning: str = '#D32F2F', success: str = '#4CAF50', neutral: str = '#666666', background: str = '#FFFFFF', text: str = '#000000', grid: str = '#E0E0E0', series: List[str] = <factory>) None[source]
Bases:
objectColor palette configuration for a theme.
- primary
Main color for primary elements
- secondary
Secondary color for supporting elements
- accent
Accent color for highlights
- warning
Color for warnings or negative values
- success
Color for positive values or success states
- neutral
Neutral gray tones
- background
Background color
- text
Text color
- grid
Grid line color
- series
List of colors for multiple data series
- class FontConfig(family: str = 'Arial', size_base: int = 11, size_title: int = 14, size_label: int = 12, size_tick: int = 10, size_legend: int = 10, weight_normal: str = 'normal', weight_bold: str = 'bold') None[source]
Bases:
objectFont configuration for a theme.
- family
Font family name
- size_base
Base font size
- size_title
Title font size
- size_label
Label font size
- size_tick
Tick label font size
- size_legend
Legend font size
- weight_normal
Normal font weight
- weight_bold
Bold font weight
- class FigureConfig(size_small: Tuple[float, float] = (6, 4), size_medium: Tuple[float, float] = (8, 6), size_large: Tuple[float, float] = (12, 8), size_blog: Tuple[float, float] = (8, 6), size_technical: Tuple[float, float] = (10, 8), size_presentation: Tuple[float, float] = (10, 7.5), dpi_screen: int = 100, dpi_web: int = 150, dpi_print: int = 300) None[source]
Bases:
objectFigure size and DPI configuration.
- size_small
Small figure size (width, height) in inches
- size_medium
Medium figure size
- size_large
Large figure size
- size_blog
Blog-optimized size (8x6)
- size_technical
Technical appendix size (10x8)
- size_presentation
Presentation slide size
- dpi_screen
DPI for screen display
- dpi_web
DPI for web publishing (150)
- dpi_print
DPI for print quality (300)
- class GridConfig(show_grid: bool = True, grid_alpha: float = 0.3, grid_linewidth: float = 0.5, spine_top: bool = False, spine_right: bool = False, spine_bottom: bool = True, spine_left: bool = True, spine_linewidth: float = 0.8, tick_major_width: float = 0.8, tick_minor_width: float = 0.4) None[source]
Bases:
objectGrid and axis configuration.
- show_grid
Whether to show grid lines
- grid_alpha
Grid transparency
- grid_linewidth
Grid line width
- spine_top
Show top spine
- spine_right
Show right spine
- spine_bottom
Show bottom spine
- spine_left
Show left spine
- spine_linewidth
Spine line width
- tick_major_width
Major tick width
- tick_minor_width
Minor tick width
- class StyleManager(theme: Theme = Theme.DEFAULT, config_path: str | Path | None = None, custom_colors: Dict[str, str] | None = None, custom_fonts: Dict[str, Any] | None = None)[source]
Bases:
objectManages visualization styles and themes.
This class provides centralized style management for all visualizations, supporting multiple themes, custom configurations, and style inheritance.
Example
>>> style_mgr = StyleManager() >>> style_mgr.set_theme(Theme.PRESENTATION) >>> style_mgr.apply_style() >>> # Create plots with consistent styling
>>> # Or with custom configuration >>> style_mgr = StyleManager(config_path="custom_style.yaml") >>> style_mgr.apply_style()
- get_colors() ColorPalette[source]
Get current color palette.
- Return type:
- Returns:
Current theme’s color palette
- get_fonts() FontConfig[source]
Get current font configuration.
- Return type:
- Returns:
Current theme’s font configuration
- get_figure_config() FigureConfig[source]
Get current figure configuration.
- Return type:
- Returns:
Current theme’s figure configuration
- get_grid_config() GridConfig[source]
Get current grid configuration.
- Return type:
- Returns:
Current theme’s grid configuration
- apply_style() None[source]
Apply current theme to matplotlib.
This updates matplotlib’s rcParams to match the current theme settings.
- Return type:
- get_figure_size(size_type: str = 'medium', orientation: str = 'landscape') Tuple[float, float][source]
Get figure size for a given type.
Module contents
Visualization infrastructure for professional report generation.
This package provides centralized styling and figure generation capabilities: - StyleManager: Manages themes, colors, fonts, and figure configurations - FigureFactory: Creates standardized plots with consistent styling
- class StyleManager(theme: Theme = Theme.DEFAULT, config_path: str | Path | None = None, custom_colors: Dict[str, str] | None = None, custom_fonts: Dict[str, Any] | None = None)[source]
Bases:
objectManages visualization styles and themes.
This class provides centralized style management for all visualizations, supporting multiple themes, custom configurations, and style inheritance.
Example
>>> style_mgr = StyleManager() >>> style_mgr.set_theme(Theme.PRESENTATION) >>> style_mgr.apply_style() >>> # Create plots with consistent styling
>>> # Or with custom configuration >>> style_mgr = StyleManager(config_path="custom_style.yaml") >>> style_mgr.apply_style()
- get_colors() ColorPalette[source]
Get current color palette.
- Return type:
- Returns:
Current theme’s color palette
- get_fonts() FontConfig[source]
Get current font configuration.
- Return type:
- Returns:
Current theme’s font configuration
- get_figure_config() FigureConfig[source]
Get current figure configuration.
- Return type:
- Returns:
Current theme’s figure configuration
- get_grid_config() GridConfig[source]
Get current grid configuration.
- Return type:
- Returns:
Current theme’s grid configuration
- apply_style() None[source]
Apply current theme to matplotlib.
This updates matplotlib’s rcParams to match the current theme settings.
- Return type:
- get_figure_size(size_type: str = 'medium', orientation: str = 'landscape') Tuple[float, float][source]
Get figure size for a given type.
- class Theme(*values)[source]
Bases:
EnumAvailable visualization themes.
- DEFAULT = 'default'
- COLORBLIND = 'colorblind'
- PRESENTATION = 'presentation'
- MINIMAL = 'minimal'
- PRINT = 'print'
- class FigureFactory(style_manager: StyleManager | None = None, theme: Theme = Theme.DEFAULT, auto_apply: bool = True)[source]
Bases:
objectFactory for creating standardized figures with consistent styling.
This class provides methods to create various types of plots with automatic application of themes, consistent formatting, and proper spacing.
Example
>>> factory = FigureFactory(theme=Theme.PRESENTATION) >>> fig, ax = factory.create_line_plot( ... x_data=[1, 2, 3, 4], ... y_data=[10, 20, 15, 25], ... title="Revenue Growth", ... x_label="Quarter", ... y_label="Revenue ($M)" ... )
>>> # Create multiple subplots >>> fig, axes = factory.create_subplots( ... rows=2, cols=2, ... size_type="large", ... subplot_titles=["Q1", "Q2", "Q3", "Q4"] ... )
- create_figure(size_type: str = 'medium', orientation: str = 'landscape', dpi_type: str = 'screen', title: str | None = None) Tuple[Figure, Axes][source]
Create a basic figure with styling applied.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes)
- create_subplots(rows: int = 1, cols: int = 1, size_type: str = 'large', dpi_type: str = 'screen', title: str | None = None, subplot_titles: List[str] | None = None, **kwargs) Tuple[Figure, Axes | ndarray][source]
Create subplots with consistent styling.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes array)
- create_line_plot(x_data: List | ndarray | Series, y_data: List | ndarray | Series | Dict[str, List | ndarray], title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', show_legend: bool = True, show_grid: bool = True, markers: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a line plot with automatic formatting.
- Parameters:
y_data (
Union[List,ndarray,Series,Dict[str,Union[List,ndarray]]]) – Y-axis data (can be multiple series as dict)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeshow_legend (
bool) – Whether to show legendshow_grid (
bool) – Whether to show gridmarkers (
bool) – Whether to add markers to lines**kwargs – Additional arguments for plot
- Return type:
- Returns:
Tuple of (figure, axes)
- create_bar_plot(categories: List | ndarray, values: List | ndarray | Dict[str, List | ndarray], title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', orientation: str = 'vertical', show_values: bool = False, value_format: str = '.1f', **kwargs) Tuple[Figure, Axes][source]
Create a bar plot with automatic formatting.
- Parameters:
values (
Union[List,ndarray,Dict[str,Union[List,ndarray]]]) – Values to plot (can be multiple series as dict)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeorientation (
str) – Bar orientation (vertical or horizontal)show_values (
bool) – Whether to show value labels on barsvalue_format (
str) – Format string for value labels**kwargs – Additional arguments for bar plot
- Return type:
- Returns:
Tuple of (figure, axes)
- create_scatter_plot(x_data: List | ndarray, y_data: List | ndarray, title: str | None = None, x_label: str | None = None, y_label: str | None = None, size_type: str = 'medium', dpi_type: str = 'screen', colors: List | ndarray | None = None, sizes: List | ndarray | None = None, labels: List[str] | None = None, show_colorbar: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a scatter plot with automatic formatting.
- Parameters:
size_type (
str) – Figure size presetdpi_type (
str) – DPI typecolors (
Union[List,ndarray,None]) – Optional colors for points (for continuous coloring)sizes (
Union[List,ndarray,None]) – Optional sizes for pointsshow_colorbar (
bool) – Whether to show colorbar when colors provided**kwargs – Additional arguments for scatter
- Return type:
- Returns:
Tuple of (figure, axes)
- create_histogram(data: List | ndarray | Series, title: str | None = None, x_label: str | None = None, y_label: str = 'Frequency', bins: int | str = 'auto', size_type: str = 'medium', dpi_type: str = 'screen', show_statistics: bool = False, show_kde: bool = False, **kwargs) Tuple[Figure, Axes][source]
Create a histogram with automatic formatting.
- create_heatmap(data: ndarray | DataFrame, title: str | None = None, x_labels: List[str] | None = None, y_labels: List[str] | None = None, x_label: str | None = None, y_label: str | None = None, size_type: str = 'medium', dpi_type: str = 'screen', cmap: str = 'RdBu_r', show_values: bool = True, value_format: str = '.2f', **kwargs) Tuple[Figure, Axes][source]
Create a heatmap with automatic formatting.
- Parameters:
- Return type:
- Returns:
Tuple of (figure, axes)
- create_box_plot(data: List[List] | Dict[str, List] | DataFrame, title: str | None = None, x_label: str | None = None, y_label: str | None = None, labels: List[str] | None = None, size_type: str = 'medium', dpi_type: str = 'screen', orientation: str = 'vertical', show_means: bool = True, **kwargs) Tuple[Figure, Axes][source]
Create a box plot with automatic formatting.
- Parameters:
data (
Union[List[List],Dict[str,List],DataFrame]) – Data for box plot (list of lists, dict, or DataFrame)size_type (
str) – Figure size presetdpi_type (
str) – DPI typeorientation (
str) – Plot orientation (vertical or horizontal)show_means (
bool) – Whether to show mean markers**kwargs – Additional arguments for boxplot
- Return type:
- Returns:
Tuple of (figure, axes)
- format_axis_currency(ax: Axes, axis: str = 'y', abbreviate: bool = True, decimals: int = 0) None[source]
Format axis labels as currency.
- format_axis_percentage(ax: Axes, axis: str = 'y', decimals: int = 0) None[source]
Format axis labels as percentages.
- add_annotations(ax: Axes, x: float, y: float, text: str, arrow: bool = True, offset: Tuple[float, float] = (10, 10), **kwargs) None[source]
Add styled annotation to plot.