01
Getting Started
Installation & First Plot
Matplotlib is the foundation of Python plotting. pyplot is the state-based interface (like MATLAB). Always call plt.show() to render the figure in a script; in Jupyter notebooks the figure renders automatically when a cell ends.
matplotlib
# install
pip install matplotlib
import matplotlib.pyplot as plt
import numpy as np
# a simple line plot
x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title("Sine Wave")
plt.xlabel("x")
plt.ylabel("sin(x)")
plt.show()pyplot State Interface
The pyplot interface mirrors MATLAB: each call operates on the 'current' figure/axes tracked internally. It is concise for quick plots but can get confusing with multiple subplots. Use plt.gcf()/plt.gca() to access the current figure/axes objects.
matplotlib