How to make multiple plots on the same figure in Matplotlib in Python

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Matplotlib is a must when you need to plot data.

Using the matplotlib.pyplot.subplots() method you can specify the number of plots you want in your figure.

Here is an example

# DataFrame library
import pandas as pd
# Graphing library
import maptplotlib.pyplot as plt

df = pd.DataFrame({"col1":range(0,10),
				   "col2":range(0,10)})

# We define the main canvas with 2 rows and 1 column
# and a height of 12 inches and a width of 6 inches
fig, axes = plt.subplots(2,1, figsize=(12,6))

# We plot the col1 on the first plot
axes[0].plot(df["col1"])

# We graph the col2 on the second plot
axes[1].plot(df["col2"])

# To make the plot nice and tidy
fig.tight_layout()

# We show the plot
plt.show()
How to do multiple plot on the same figure in Matplotlib

Here you are! You now know how to make multiple plots on the same figure in Matplotlib in Python.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.