1

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 was not able to use this solution.

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

df1.set_index('Date').plot(ax=axes[0,0])
df2.set_index('Date').plot(ax=axes[0,1])
df3.set_index('Date').plot(ax=axes ??? ) 

How do I need to assign the axes (if at all possible) in order to get something like this:

enter image description here

Joe
  • 12,057
  • 5
  • 39
  • 55
rul30
  • 463
  • 1
  • 7
  • 17
  • Then don't use the pandas plot. You can just use matplotlib with something like `plot_date(df3.index, df3[0], '-')`. I've you'd given a [mcve], I'could have shown this in an answer. – JHBonarius Jul 31 '18 at 06:26

2 Answers2

2

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

Joe
  • 12,057
  • 5
  • 39
  • 55
0

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

rul30
  • 463
  • 1
  • 7
  • 17