Categories
Python Answers

How to plot separate Python Pandas DataFrames as subplots?

Spread the love

Sometimes, we want to plot separate Python Pandas DataFrames as subplots.

In this article, we’ll look at how to plot separate Python Pandas DataFrames as subplots.

How to plot separate Python Pandas DataFrames as subplots?

To plot separate Python Pandas DataFrames as subplots, we can create subplots with matplotlib.

For instance, we write

import matplotlib.pyplot as plt

fig, axes = plt.subplots(nrows=2, ncols=2)

df1.plot(ax=axes[0,0])
df2.plot(ax=axes[0,1])

to call plt.subplots to create the subplots.

Then we call plot on the data frames with the ax argument set to the location of the subplot.

Conclusion

To plot separate Python Pandas DataFrames as subplots, we can create subplots with matplotlib.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *