I use the irf function of statsmodels to produce a plot. Then, I use ax1 = fig.add_subplot(211)
to add a subplot to that figure. The code looks like:
irf = results.irf()
fig = irf.plot( plot_stderr= False, impulse = columns[1], response = columns[0])
ax1 = fig.add_subplot(211)
ax1.plot(df[columns].dropna().index, df[columns].dropna().iloc[:, 1], color='red')
ax1.tick_params(axis='y', labelcolor='red')
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
ax2.plot(df[columns].dropna().index, df[columns].dropna().iloc[:, 0], color='blue')
ax2.tick_params(axis='y', labelcolor='blue')
plt.subplots_adjust(hspace = 10)
This produces:
Problem: as you can see, the lower plot (irf plot) is clipped off. When I add plt.subplots_adjust(hspace = 10)
, I get:
This helps a bit but at the cost of reducing the size of the top subplot, which is undesirable.
Question: How can I get both subplots of equal size without any clippings. I wish I could start with fig, (ax1, ax2) = plt.subplots(2,1)
and then pass ax1 to the irf.plot(). Then I could have control over both axes. But apparently there is no way to pass an ax to irf.plot(). it just creates its own figure. I would even be satisfied with creating the two figures separately and then joining them and saving them as one figure, if there is a way for that.