【问题标题】:ticks on right side of plot un subplots enviroment子图环境中图右侧的刻度
【发布时间】:2019-11-06 00:34:19
【问题描述】:

我正在尝试在右侧获取我的情节的刻度。 (右下角的那个)我试过很多相关的话题。例如。 Python Matplotlib Y-Axis ticks on Right Side of Plot matplotlib y-axis label on right side

但似乎没有任何效果。如果我在 ax 环境中做错了什么,有人可以看看吗?我在 python 2.7 顺便说一句。

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()

【问题讨论】:

  • 除了ax6.xlabel('Wavelength ($\mathrm{\AA}$)') 这行需要ax6.set_xlabel('Wavelength ($\mathrm{\AA}$)')之外,你的代码对我来说很好用
  • 按照this 回答试试这个ax6.tick_params(axis='y', which='both', labelleft='off', labelright='on')
  • 在我修复了 xlabel 后,斧头移动了,但数字不见了。第二个也不起作用。
  • 知道了!必须添加ax6.update_ticks()
  • 您可以将此添加为自我回答,然后接受它。另外,请在您的回答中指定您使用的是哪个 matplotlib 和 python 版本

标签: python python-2.7 matplotlib plot axes


【解决方案1】:

所以有效的方法是将ax6.update_ticks() 添加到脚本的末尾。这是 python 2.7。

【讨论】:

    猜你喜欢
    • 2012-05-08
    • 1970-01-01
    • 1970-01-01
    • 2015-01-30
    • 1970-01-01
    • 2021-10-29
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多