Categories
Python Answers

How to plot separate Pandas DataFrames as subplots?

Spread the love

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

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

How to plot separate Pandas DataFrames as subplots?

To plot separate Pandas DataFrames as subplots, we can use the plot method.

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 a page with subplots.

Then we call plot on each dataframe with the ax argument set to the location we want to put the subplot of the dataframe.

Conclusion

To plot separate Pandas DataFrames as subplots, we can use the plot method.

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 *