Menu Close

How to plot separate Python Pandas DataFrames as subplots?

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.

Posted in Python, Python Answers