Typography affects how professional and readable a chart feels. Matplotlib lets you control fonts, sizes and weights, and even render mathematical notation with LaTeX-style syntax.
Font control
ax.set_title("Results", fontsize=16, fontweight="bold", fontfamily="serif")ax.set_xlabel("time", fontsize=12)plt.rcParams["font.family"] = "DejaVu Sans" # set globally
Math text
Wrap expressions in $...$ for LaTeX-style maths in any label or title:
ax.set_xlabel(r"$\theta$ (radians)")ax.set_title(r"$y = x^2 + \sqrt{x}$")ax.text(2, 5, r"$\bar{x} = \frac{1}{n}\sum x_i$")
Key takeaways
- 01Control fontsize, fontweight and fontfamily per element or globally via rcParams.
- 02Wrap expressions in $...$ for LaTeX-style mathematical notation.
- 03Use raw strings r"..." for math text to preserve backslashes.
- 04Keep text large enough to read at the final display size.
