Home > Net >  In Matplotlib how do I get left and right Y axes with the same scale but different labels with only
In Matplotlib how do I get left and right Y axes with the same scale but different labels with only

Time:10-01

Using the code below (and with the help of this really good page: enter image description here

CodePudding user response:

You can use secondary_yaxis() to set a second y-axis on the other side for the same plot. Also, as you indicated that you want to show the ticks at 0.5 distance, you can use set_yticks() for that. Add these two lines just before the plt.show()

ax2 = ax.secondary_yaxis("right")
ax2.set_yticks(np.arange(0, max(df['Ach_Num']) .5, 0.5))

Updated plot (using random data)

enter image description here

  • Related