|
| 1 | +""" |
| 2 | +🎨 Matplotlib Style Configuration (Light & Dark Mode Compatible) |
| 3 | +
|
| 4 | +This module provides universal matplotlib settings that work in both light and dark themes. |
| 5 | +Import with: from plot_config import setup_matplotlib_style |
| 6 | +Then call: setup_matplotlib_style() |
| 7 | +
|
| 8 | +Features: |
| 9 | +- High-quality output (500 DPI display, 300 DPI saved) |
| 10 | +- Transparent backgrounds for theme adaptation |
| 11 | +- Dark gray text that's readable on both backgrounds |
| 12 | +- Computer Modern math font |
| 13 | +""" |
| 14 | + |
| 15 | +import matplotlib |
| 16 | +import matplotlib.pyplot as plt |
| 17 | + |
| 18 | + |
| 19 | +def setup_matplotlib_style(): |
| 20 | + """ |
| 21 | + Configure matplotlib for high-quality, theme-agnostic plots. |
| 22 | + |
| 23 | + This function sets up: |
| 24 | + - High-quality output (500 DPI display, 300 DPI save) |
| 25 | + - Transparent backgrounds |
| 26 | + - Dark gray text for readability on both light and dark backgrounds |
| 27 | + - Computer Modern fonts for professional appearance |
| 28 | + """ |
| 29 | + |
| 30 | + # Use mathtext with Computer Modern and avoid external TeX |
| 31 | + matplotlib.rcParams['text.usetex'] = False |
| 32 | + matplotlib.rcParams['mathtext.fontset'] = 'cm' |
| 33 | + matplotlib.rcParams['font.family'] = 'serif' |
| 34 | + matplotlib.rcParams['font.serif'] = ['DejaVu Serif', 'Nimbus Roman', 'Times New Roman', 'Times'] |
| 35 | + |
| 36 | + # Universal matplotlib settings that work in both light and dark mode |
| 37 | + matplotlib.rcParams.update({ |
| 38 | + # High-quality output |
| 39 | + 'figure.dpi': 300, # Display DPI (screen) |
| 40 | + 'savefig.dpi': 300, # Save DPI (high quality for web) |
| 41 | + 'figure.figsize': (10, 6), # Default figure size in inches (max width) |
| 42 | + |
| 43 | + }) |
| 44 | + |
| 45 | + |
| 46 | +# Apply configuration when module is imported |
| 47 | +setup_matplotlib_style() |
0 commit comments