PYTHON APPLIEDChapter 13 · Python for Data Science
Visualizing data with Matplotlib
Matplotlib is Python's foundational plotting library. Its pyplot interface lets you create line plots, bar charts, scatter plots, and histograms with just a few function calls.
Worked example
import matplotlib.pyplot as plt
months = ["Jan", "Feb", "Mar", "Apr", "May"]
temps = [2, 5, 11, 16, 21]
plt.figure(figsize=(8, 4))
plt.plot(months, temps, marker="o", color="#7b68ee")
plt.title("Average Temperature")
plt.ylabel("Celsius")
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig("temps.png")
plt.show()How it reads
- plt.plot(x, y) draws a line chart connecting the data points
- marker='o' adds circular markers at each data point
- plt.savefig('temps.png') saves the chart to an image file

Cloud tip: For quick DataFrame plots, use df.plot() directly. It calls Matplotlib under the hood but saves you from manual axis setup.


