Skip to content
Matplotlib

Styles and Themes

Apply built-in styles and customize rcParams.

#styles#theme#rcparams

Code

matplotlib
import matplotlib.pyplot as plt
import numpy as np

# List available styles
print(plt.style.available[:5])

# Apply a style context temporarily
with plt.style.context("ggplot"):
    x = np.linspace(0, 1, 50)
    plt.plot(x, x ** 2, label="x^2")
    plt.plot(x, np.sqrt(x), label="sqrt")
    plt.legend()
    plt.show()

# Global rcParams customization
plt.rcParams.update({
    "figure.figsize": (8, 4),
    "font.size": 12,
    "axes.grid": True,
    "lines.linewidth": 2,
})