bio-data-visualization-matplotlib-fundamentals
Installation
SKILL.md
Version Compatibility
Reference examples tested with: matplotlib 3.8+, seaborn 0.13+, numpy 1.26+, pandas 2.2+.
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
matplotlib Fundamentals
"Make a publication figure in Python" -> Build via the object-oriented Figure/Axes API (not pyplot state-machine), with constrained_layout for axes alignment, pdf.fonttype=42 for journal-compliant TrueType fonts, CVD-safe palettes, and rasterized point layers for large scatter. The pyplot interface is for notebook scratch; the Figure/Axes API is for reproducible figures.
- Python:
fig, ax = plt.subplots()->ax.scatter/ax.plot/ax.bar;seaborn.objects(new grammar API) for ggplot-like
The Three Modern Defaults
- Object-oriented API —
fig, ax = plt.subplots(figsize=(4, 3))thenax.scatter(x, y),ax.set_xlabel(...). The pyplot state-machine (plt.scatter,plt.xlabel) hides which axes are being modified and breaks in multi-subplot figures.