Menu Close

How to plot separate Pandas DataFrames as subplots?

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.

Posted in Python, Python Answers