Skip to content Skip to sidebar Skip to footer

How To Make An Axes Occupy Multiple Subplots When Using Pandas Datetime Plot?

I would like to create a (sub)plot with two rows and two columns where the plot in the lower row occupies both axes. Since I use the plot from within pandas datetime (I think) I wa

Solution 1:

You can do in this way for example:

df = pd.DataFrame( {'date':['2010-01-01','2010-01-02','2010-01-03'],'a1':[5,4,3],'a2':[6,2,9]})
df['date'] = pd.to_datetime(df['date'])
import matplotlib.pyplot as plt
fig = plt.figure()

ax1 = plt.subplot(221)
ax2 = plt.subplot(222)
ax3 = plt.subplot(212)

df.plot(x="date", y='a1',ax=ax1)
df.plot(x="date", y='a2',ax=ax2)
df.plot(x="date", y=['a1','a2'], ax=ax3)

plt.tight_layout()
plt.show()

enter image description here

Solution 2:

For completeness only I am posting the code-snippet which resulted from the help of stackoverflow. The datetime of the two sensor readings is not synchronized, so I could not plot as suggested.

fig = plt.figure()

ax1 = plt.subplot(221)
ax2 = plt.subplot(222)
ax3 = plt.subplot(212)

df1.plot(x='Date', y='series1',ax=ax1)
df2.plot(x='Date', y='series2',ax=ax2)
df1.plot(x='Date', y='series1',ax=ax3)
df2.plot(x='Date', y='series2',ax=ax3)

plt.tight_layout()
plt.show()

enter image description here

Post a Comment for "How To Make An Axes Occupy Multiple Subplots When Using Pandas Datetime Plot?"