Skip to main content
Albero Academy

Text & Fonts

Control typography, math notation and text placement.

Styling & Themes7 min

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

size, weight, family
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:

mathematical notation
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

  1. 01Control fontsize, fontweight and fontfamily per element or globally via rcParams.
  2. 02Wrap expressions in $...$ for LaTeX-style mathematical notation.
  3. 03Use raw strings r"..." for math text to preserve backslashes.
  4. 04Keep text large enough to read at the final display size.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.