You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Matplotlib is the foundational plotting library in Python. Nearly every other Python visualisation library (Seaborn, Pandas plotting, even some Plotly features) is built on top of or integrates with Matplotlib. Understanding its architecture gives you complete control over every element of a chart.
pip install matplotlib
The standard import convention:
import matplotlib.pyplot as plt
import numpy as np
Matplotlib offers two ways to create plots:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Simple Line Plot")
plt.show()
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4], [10, 20, 25, 30])
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_title("Simple Line Plot")
plt.show()
Tip: Always use the object-oriented interface (
fig, ax = plt.subplots()) for anything beyond the simplest plot. It gives you explicit control over figures and axes.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.