AI is visual. Whether it's diagnosing models or presenting data, we need charts. Matplotlib is the standard visualization library.
We typically import the pyplot module from Matplotlib as plt.
The most basic ways to visualize data are connecting points with lines or plotting individual dots.
Toggle configuration options, switch chart styles, and see the generated Python code.
import matplotlib.pyplot as plt
epochs = [1,2,3,4,5]
loss = [2.5,1.8,1.2,0.8,0.5]
plt.plot(epochs, loss, marker='o', color='indigo')
plt.title("Training Loss Curve")
plt.xlabel("Epoch")
plt.ylabel("Loss")
plt.grid(True)
plt.legend(["Training Loss"])
plt.show()A graph is useless without labels! You should always add titles and axis labels.
In ML, we often plot distributions to understand our data, or loss curves to see how our model is learning.
plt.hist(data) - Histograms (for distribution)plt.bar(labels, heights) - Bar charts (for categorical comparisons)When an AI model trains, its "loss" (error) should go down over time. Let's visualize this!
epochs = [1, 2, 3, 4, 5].loss_values = [2.5, 1.8, 1.2, 0.8, 0.5].plt.plot() to draw a line graph of epochs vs. loss values. Add a marker style like marker='o' to see the exact points.plt.show() to display it.