Matplotlib is the workhorse plotting library for Python. In the ML notebooks, it is used to visualise training curves, decision boundaries, data distributions, weight matrices, and sample images. Most plotting is done through theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ageron/handson-ml3/llms.txt
Use this file to discover all available pages before exploring further.
pyplot interface, which mirrors MATLAB’s plotting API and keeps a global figure and axes state for quick interactive use.
First plot
In Jupyter, importing
matplotlib.pyplot automatically registers Jupyter as a backend so plots render inline. You may still see %matplotlib inline in older notebooks — this was required in older Jupyter versions but is no longer necessary.Labels, title, and grid
Line style and color
The third argument toplt.plot sets the line style and color in one compact string. "g--" means green dashed line; "r-" means red solid:
Scatter plots
Scatter plots are used extensively in ML to visualise feature relationships, cluster assignments, and classification results:Histograms
Histograms help inspect the distribution of any numeric variable — feature values, prediction scores, or residuals:Subplots
plt.subplot(rows, cols, index) divides the figure into a grid of panels. In the ML notebooks this is used to compare multiple plots side by side, for instance to show training vs. validation loss:
Displaying images with imshow
plt.imshow renders a 2D array as a heatmap or a 3D (H × W × 3) array as an RGB image. It appears in the notebooks whenever MNIST digits, convolutional feature maps, or confusion matrices are displayed:
Saving figures
savefig before plt.show() — once show() is called the figure is cleared.
Figure size
Control figure dimensions (in inches) with thefigsize parameter: