I am working on a multi axes plot. I have troubble in setting the ylims of each sub plot. I am not providing the data as the problem is related to setting the axes only.
Here is the code:
ax1 = plt.subplot(411)
plt.plot(x,y1,'-r')
ax2 = plt.subplot(412,sharex=ax1)
plt.plot(x,y2,'-g')
ax3 = plt.subplot(413,sharex=ax1)
plt.plot(x,y3,'-k')
ax4 = plt.subplot(414,sharex=ax1)
plt.plot(x,y4,'-b')
ax1.get_shared_x_axes().join(ax1,ax2,ax3,ax4)
#make x axis on upper invisible
plt.setp(ax1.get_xaxis(), visible=False)
plt.setp(ax2.get_xaxis(), visible=False)
ax1.spines['bottom'].set_visible(False)
ax1.set_ylim([20,40])
ax2.spines['top'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax2.set_ylim([0,0.8])
ax3.spines['top'].set_visible(False)
ax3.spines['bottom'].set_visible(False)
ax4.spines['top'].set_visible(False)
ax1.grid(axis="y")
ax2.grid(axis="y")
ax3.grid(axis="y")
ax4.grid(axis="y")
plt.subplots_adjust(hspace=0.01)
ax4.set_xlabel('Time (s)')
plt.subplots_adjust(left=0.12, right=0.97, top=0.95, bottom=0.15)
plt.show()
Existing output: We see the ylim of subplot1 has been reset. But, ax2 and ax3 y limits did not change.
0.5is not on top ofax2, that small distance would account for the space from0.5to0.8.