我正在尝试在右侧显示我的图的刻度。 (他在右下角的一个诠释)我尝试了许多相关主题。例如。 Python Matplotlib Y-Axis ticks on Right Side of Plot matplotlib y-axis label on right side
但是似乎没有任何效果。有人可以看看我是否在斧头环境中做错了什么吗?我在python 2.7 btw上。
step_1 = step_2 = step_3 = step_4 = step_5 = np.random.random((300,300))
u1 = u2 = u3 = u4 = u5 = wav = np.random.random(30)
o = 20
fig, axs = plt.subplots(2, 3, gridspec_kw={'hspace': 0, 'wspace': 0})
(ax1, ax2, ax3),(ax4, ax5, ax6) = axs
im1 = ax1.imshow(step_1, origin='lower', cmap='gray', extent=[xb,xe,yb,ye], aspect='auto')
#630,475 = 81,-546
ax1.scatter(-555,70, marker='x', color='red')
ax1.set_xticklabels([])
im2 = ax2.imshow(step_2, origin='lower', cmap='gray', extent=[xb,xe,yb,ye], aspect='auto')
ax2.scatter(-555,70,marker='x', color='red')
ax2.set_yticklabels([])
im3 = ax3.imshow(step_3, origin='lower', cmap='gray', extent=[xb,xe,yb,ye], aspect='auto')
ax3.scatter(-555,70,marker='x', color='red')
ax3.set_yticklabels([])
im4 = ax4.imshow(step_4, origin='lower', cmap='gray', extent=[xb,xe,yb,ye], aspect='auto')
ax4.scatter(-555,70,marker='x', color='red')
im5 = ax5.imshow(step_5, origin='lower', cmap='gray', extent=[xb,xe,yb,ye], aspect='auto')
ax5.scatter(-555,70,marker='x', color='red')
ax5.set_yticklabels([])
im6 = ax6.plot(wav, u1/o, label='Step 1', color='lightcoral', alpha=0.6)
ax6.plot(wav, u2/o, label='Step 2', color='indianred', alpha=0.7)
ax6.plot(wav, u3/o, label='Step 3', color='brown', alpha=0.8)
ax6.plot(wav, u4/o, label='Step 4', color='firebrick', alpha=0.9)
ax6.plot(wav, u5/o, label='Step 5', color='darkred', linewidth=3.)
ax6.legend()
ax6.ticklabel_format(axis='y', style='sci', scilimits=(-2,2))
ax6.xlabel('Wavelength ($\mathrm{\AA}$)')
ax6.yaxis.tick_right()
ax6.yaxis.set_ticks_position('both')
plt.show()
答案 0 :(得分:0)
所以有效的方法是在脚本的末尾添加ax6.update_ticks()
。这是python 2.7。