0

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.

3
  • 1
    Have you tried also giving set_yticks([0,0.8]) ? By the way I couldn’t see ylim given for ax3 in your code. You can also try using matplotlib and subplots and then plt for each subplot instead of setting an ax foreach subplot. Have you tried? Commented Jun 5, 2020 at 3:48
  • 1
    I think your code work, notice how 0.5 is not on top of ax2, that small distance would account for the space from 0.5 to 0.8. Commented Jun 5, 2020 at 4:05
  • @QuangHoang That's right. I noticed it lately. It is working fine. Thanks a ton. Commented Jun 5, 2020 at 4:42

1 Answer 1

1

From @QuangHoang in the comments:

I think your code work, notice how 0.5 is not on top of ax2, that small distance would account for the space from 0.5 to 0.8.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.