Skip to content

Introduction to Matplotlib

What is Matplotlib?

Matplotlib is the core plotting library in Python.

  • Flexible and powerful
  • Works everywhere (scripts, notebooks)
  • Backbone for many libraries (including Seaborn)

Two common ways to plot

1) Pyplot (quick)

pyplot quick
import matplotlib.pyplot as plt
 
plt.plot([1, 2, 3], [3, 2, 5])
plt.title("Quick plot")
plt.show()
pyplot quick
import matplotlib.pyplot as plt
 
plt.plot([1, 2, 3], [3, 2, 5])
plt.title("Quick plot")
plt.show()
OO API
import matplotlib.pyplot as plt
 
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot([1, 2, 3], [3, 2, 5])
ax.set_title("OO plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.show()
OO API
import matplotlib.pyplot as plt
 
fig, ax = plt.subplots(figsize=(7, 4))
ax.plot([1, 2, 3], [3, 2, 5])
ax.set_title("OO plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
plt.show()

Key terms

  • Figure: the whole canvas
  • Axes: the plotting area
  • Artist: everything drawn on the figure

In this phase, we’ll focus on practical charts you need for analytics.

If this helped you, consider buying me a coffee β˜•

Buy me a coffee

Was this page helpful?

Let us know how we did