Visualizing Math Concepts with Matplotlib
Seeing a concept is faster than reading about it. A loss curve tells you in one glance whether your model is training, overfitting, or stuck. A plot of a function shows you where its minimum is. Matplotlib is the standard plotting library for Python, and a handful of its functions cover 90% of what you'll need in AI.
Plotting Functions: The Basics
The core workflow is always the same: create an array of x-values with np.linspace(), compute y-values, and call plt.plot(). np.linspace(a, b, n) creates n evenly-spaced points between a and b.
Plotting a Loss Landscape
Visualizing Gradient Descent
Plotting the path of gradient descent on a function helps you understand learning rates intuitively. A path that zigzags wildly means the learning rate is too high; one that barely moves means it's too low.
Tracking the Optimization Path
Plotting Distributions
Histograms and density plots let you inspect whether your data follows the distribution you expect — critical for diagnosing data quality issues before training.