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. Created by John D. Hunter in 2003, it provides a MATLAB-like interface for creating static, animated, and interactive visualisations. While there are many visualisation libraries in Python (Seaborn, Plotly, Altair), Matplotlib is the one they are all built on — understanding it gives you complete control over your plots.
Matplotlib offers two ways to create plots:
import matplotlib.pyplot as plt
import numpy as np
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.title('Simple Line Plot')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
fig, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple Line Plot')
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
plt.show()
The object-oriented interface gives you more control and is the recommended approach for anything beyond quick plots.
Every Matplotlib plot has two key objects:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.