themes¶
The themes module provides complete MSU theming for matplotlib plots.
Module Overview¶
This module provides:
- Complete MSU theme application
- Seaborn style integration
- Theme reset functionality
- Automatic font registration
Functions¶
theme_msu(base_size=11, base_family='Metropolis', use_grid=False, grid_color='#E5E5E5', grid_linewidth=0.8, spine_color='#000000', spine_linewidth=1.0, color_cycle=None, register_fonts=True)
¶
Apply MSU theme to matplotlib plots.
This function sets matplotlib rcParams to use MSU branding including: - Metropolis font (automatically registered) - MSU color palette - Clean, professional styling - Optional grid lines
Args: base_size: Base font size for all text elements (default: 11) base_family: Font family to use (default: "Metropolis") use_grid: Whether to show grid lines (default: False) grid_color: Color of grid lines (default: "#E5E5E5") grid_linewidth: Width of grid lines (default: 0.8) spine_color: Color of axis spines (default: "#000000") spine_linewidth: Width of axis spines (default: 1.0) color_cycle: Custom color cycle (default: MSU colors) register_fonts: Whether to register Metropolis fonts (default: True)
Returns: Dictionary of applied rcParams
Examples: >>> from msuthemes import theme_msu >>> import matplotlib.pyplot as plt >>> >>> # Apply MSU theme >>> theme_msu() >>> >>> # Create plot with MSU styling >>> plt.plot([1, 2, 3], [1, 4, 2]) >>> plt.title('MSU Plot') >>> plt.show()
>>> # Apply theme with grid
>>> theme_msu(use_grid=True)
>>> # Apply theme with larger font
>>> theme_msu(base_size=14)
Source code in msuthemes/themes.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
set_msu_style(style='white', context='notebook', palette=None, font='Metropolis', font_scale=1.0, register_fonts=True)
¶
Set MSU styling for seaborn plots.
This function configures seaborn with MSU branding including colors, fonts, and styling preferences.
Args: style: Seaborn style ('white', 'whitegrid', 'dark', 'darkgrid', 'ticks') Default: 'white' context: Seaborn context ('paper', 'notebook', 'talk', 'poster') Default: 'notebook' palette: Custom color palette (default: MSU colors) font: Font family (default: 'Metropolis') font_scale: Scale factor for fonts (default: 1.0) register_fonts: Whether to register Metropolis fonts (default: True)
Examples: >>> from msuthemes import set_msu_style >>> import seaborn as sns >>> import matplotlib.pyplot as plt >>> >>> # Apply MSU style to seaborn >>> set_msu_style() >>> >>> # Create seaborn plot >>> tips = sns.load_dataset('tips') >>> sns.scatterplot(data=tips, x='total_bill', y='tip') >>> plt.show()
>>> # Use with whitegrid style
>>> set_msu_style(style='whitegrid')
>>> # Use for presentation
>>> set_msu_style(context='talk', font_scale=1.2)
Source code in msuthemes/themes.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
reset_theme()
¶
Reset matplotlib to default settings.
This function restores matplotlib's default rcParams, removing any MSU theme customizations.
Examples: >>> from msuthemes import theme_msu, reset_theme >>> >>> # Apply MSU theme >>> theme_msu() >>> >>> # ... create plots ... >>> >>> # Reset to defaults >>> reset_theme()
Source code in msuthemes/themes.py
Usage Examples¶
Basic Theme Application¶
from msuthemes import theme_msu
import matplotlib.pyplot as plt
# Apply MSU theme
theme_msu()
# Create plot
plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.title('MSU-Themed Plot')
plt.show()
Customized Theme¶
from msuthemes import theme_msu
import matplotlib.pyplot as plt
# Apply theme with customization
theme_msu(
base_size=12,
grid=True,
spines='bl'
)
# Create plot
plt.plot([1, 2, 3, 4], [1, 4, 2, 3])
plt.show()
Seaborn Integration¶
from msuthemes import set_msu_style
import seaborn as sns
import matplotlib.pyplot as plt
# Apply MSU style to seaborn
set_msu_style()
# Create seaborn plot
sns.boxplot(data=data)
plt.show()
Resetting Theme¶
from msuthemes import theme_msu, reset_theme
import matplotlib.pyplot as plt
# Apply MSU theme
theme_msu()
plt.plot([1, 2, 3], [1, 4, 2])
plt.show()
# Reset to defaults
reset_theme()
plt.plot([1, 2, 3], [1, 4, 2])
plt.show()
Different Spine Configurations¶
from msuthemes import theme_msu
import matplotlib.pyplot as plt
# Only bottom and left spines (default)
theme_msu(spines='bl')
plt.plot([1, 2, 3], [1, 4, 2])
plt.show()
# All spines
theme_msu(spines='all')
plt.plot([1, 2, 3], [1, 4, 2])
plt.show()
# No spines
theme_msu(spines='none')
plt.plot([1, 2, 3], [1, 4, 2])
plt.show()
Presentation vs Publication¶
from msuthemes import theme_msu
import matplotlib.pyplot as plt
# Larger text for presentations
theme_msu(base_size=14, grid=True)
plt.plot([1, 2, 3], [1, 4, 2])
plt.title('Presentation Figure')
plt.show()
# Smaller text for publications
theme_msu(base_size=9, grid=False, spines='bl')
plt.plot([1, 2, 3], [1, 4, 2])
plt.title('Publication Figure')
plt.show()
Theme Components¶
The MSU theme modifies these matplotlib rcParams:
Fonts¶
- Font family: Metropolis
- Scaled font sizes based on
base_sizeparameter
Colors¶
- Color cycle using MSU colors
- Axes colors and backgrounds
- Grid colors
Layout¶
- Figure size and DPI
- Axes line widths
- Grid line styles
Spines¶
- Configurable axes borders
- Options: 'bl', 'all', 'none', or combinations
See Also¶
- Theme Guide - Detailed theme usage guide
- Fonts - Font management
- Gallery - Themed examples