Chapter 12 of 30
Keep learning and build your Data Science skills.
Matplotlib
Learn how to create charts and graphs using Matplotlib.
Theory
Matplotlib is a Python visualization library.
It can create:
• Line charts
• Bar charts
• Histograms
• Scatter plots
• Pie charts
• Box plots
Matplotlib provides detailed control over labels, axes, titles, and other chart elements.
Example
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 15, 30]
plt.plot(x, y)
plt.title("Example Chart")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()Output
A line chart is displayed using Matplotlib.
Practice
Create a bar chart using Matplotlib.
Interview Questions
1
What is Matplotlib?
2
What types of charts can Matplotlib create?
3
How do you add a chart title?
Quick Quiz
Which option best describes this chapter?
A.Matplotlib
B.Pandas
C.NumPy
D.Scikit-learn