Plotting¶
Figures do a lot of work in a physics paper or talk. A clear figure makes a complex result easy to follow; a poorly designed one can obscure it entirely. This track covers how to design figures that communicate well and how to produce them efficiently using matplotlib and the Nestling style file.
Acknowledgement
Several lessons in this track draw on Ciaran O'Hare's HowToMakeAPlot, a concise and practical guide to scientific plotting in Python.
Lessons¶
- Lesson 01: Figure Design Principles: What makes a good scientific figure: clarity, honesty, and accessibility.
- Lesson 02: matplotlib Basics: Creating line plots, scatter plots, histograms, and multi-panel figures.
- Lesson 03: Publication Style: Using the Nestling matplotlib style, LaTeX labels, and exporting to PDF.
- Lesson 04: Colour and Accessibility: Choosing colourblind-friendly palettes and avoiding common pitfalls.
Examples¶
See the examples/plotting/ folder
for runnable scripts demonstrating basic and publication-quality plots.
The Nestling matplotlib style file is at examples/plotting/styles/nestling.mplstyle.
Quick-start¶
import matplotlib.pyplot as plt
from pathlib import Path
STYLE = Path("examples/plotting/styles/nestling.mplstyle")
plt.style.use(str(STYLE))
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9], label=r"$x^2$")
ax.set_xlabel(r"$x$")
ax.set_ylabel(r"$y$")
ax.legend()
plt.tight_layout()
plt.savefig("figure.pdf", bbox_inches="tight")
plt.close(fig)