Heuristic:AI4Finance Foundation FinGPT Seaborn Styled Plots
| Knowledge Sources | |
|---|---|
| Domains | Visualization, Portfolio_Analytics |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
A styling heuristic that applies seaborn-style plotting contexts and axes themes to matplotlib figures in the vendored pyfolio package, ensuring consistent visual appearance across all tear sheet plots.
Description
The Seaborn Styled Plots heuristic is implemented via the `customize` decorator in pyfolio's `plotting` module. Each plotting function is wrapped with seaborn's `plotting_context` and `axes_style` context managers, which temporarily set matplotlib rcParams to produce consistent, publication-quality figures. The default context is `'notebook'` with `font_scale=1.5`, and the default style is `'darkgrid'`. The `customize` decorator ensures that every plot function applies these styles uniformly.
Usage
Apply this heuristic when generating pyfolio tear sheets or individual plots to ensure consistent styling. Required by the pyfolio plotting module.
Theoretical Basis
def customize(func):
"""Decorator to set plotting context and axes style during function call."""
@wraps(func)
def wrapper(*args, **kwargs):
with plotting_context(context='notebook', font_scale=1.5), \
axes_style(style='darkgrid'):
return func(*args, **kwargs)
return wrapper
@customize
def plot_returns(returns, live_start_date=None, ax=None, **kwargs):
...
The seaborn context managers temporarily modify matplotlib's rcParams, restoring the original settings after the plot function returns.
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: seaborn` | seaborn not installed | `pip install seaborn` |
| `Style not found: darkgrid` | seaborn version too old | Upgrade seaborn >= 0.12.0 |
Compatibility Notes
- Fallback: If seaborn is not installed, pyfolio falls back to a no-op context manager via `_seaborn.py` which suppresses the import warning.
- Context names: Available contexts: `paper`, `notebook`, `talk`, `poster`.
- Style names: Available styles: `darkgrid`, `whitegrid`, `dark`, `white`, `ticks`.