statspai.plots¶
plots ¶
Visualization module for StatsPAI.
Provides publication-quality academic plots: - binscatter: Binned scatter plots with residualization (Cattaneo et al. 2024) - coefplot: Coefficient comparison forest plots - event_study_plot: DID event study (via CausalResult) - rdplot: RD visualization (via rd module) - marginsplot: Marginal effects (via postestimation) - interactive: Interactive plot editor with data protection
set_theme ¶
Set global matplotlib theme for publication-quality plots.
Supports three theme sources:
- StatsPAI:
'academic','aea','minimal','cn_journal' - matplotlib:
'ggplot','fivethirtyeight','bmh','dark_background','grayscale','classic', etc. - seaborn:
'seaborn-whitegrid','seaborn-darkgrid','seaborn-ticks','seaborn-paper','seaborn-talk', etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Theme name. Use |
'academic'
|
palette
|
str
|
Color palette name. Defaults to matching the theme. Only applies to StatsPAI themes. |
None
|
font_scale
|
float
|
Scale factor for all font sizes. |
1.0
|
Examples:
>>> import statspai as sp
>>> sp.set_theme('academic') # clean serif, no top/right spines
>>> sp.set_theme('aea') # AER journal specifications
>>> sp.set_theme('ggplot') # R ggplot2 style
>>> sp.set_theme('seaborn-whitegrid') # seaborn white grid
>>> sp.set_theme('fivethirtyeight') # FiveThirtyEight journalism style
>>> sp.set_theme('dark_background') # dark theme for slides
>>> sp.set_theme('default') # reset to matplotlib defaults
list_themes ¶
use_chinese ¶
One-line fix for Chinese text rendering in matplotlib.
Call this before creating any plots. Automatically detects the best Chinese font on your system (macOS, Windows, Linux).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
style
|
str
|
|
'auto'
|
Returns:
| Type | Description |
|---|---|
str
|
The font name that was configured. |
Examples: