Visualisation turns raw numbers into physical insight. A well-chosen plot can reveal patterns that spreadsheets hide.
Matplotlib basics
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2 * np.pi, 200)
plt.plot(t, np.sin(t), label="sin(t)")
plt.plot(t, np.cos(t), label="cos(t)")
plt.xlabel("Time (s)")
plt.ylabel("Amplitude")
plt.title("Simple Harmonic Motion")
plt.legend()
plt.grid(True)
plt.show()
Essential plot types for physics
| Plot | Use case |
|---|---|
| Line plot | Time series, trajectories |
| Scatter plot | Experimental data points |
| Histogram | Distribution of measurements |
| Contour / heatmap | 2D scalar fields (temperature, potential) |
| Vector field | Force or velocity fields |
Good visualisation practices
- Always label axes with units.
- Use a legend when multiple series appear.
- Choose a colour map appropriate for the data (sequential for magnitudes, diverging for deviations from zero).
- Add error bars for experimental data:
plt.errorbar(x, y, yerr=err).
Tip: Save figures in vector format (plt.savefig("plot.pdf")) for publications. PNG is fine for quick inspection but loses quality when scaled.
Common pitfall: Axis choices can manufacture or hide stories: truncated y-axes exaggerate trends, log scales linearize exponentials. Read (and label) the axes before believing any plot — including your own.