Python MatplotLib仅在顶部和右侧轴内侧移动记号

Python MatplotLib仅在顶部和右侧轴内侧移动记号,python,matplotlib,plot,axis,xticks,Python,Matplotlib,Plot,Axis,Xticks,我希望将绘图上的刻度移到内部,但只移到顶部和右侧轴上。 这是我正在使用的代码 ax.tick_params(top=True, right=True, which='both') ax.xaxis.set_minor_locator(AutoMinorLocator(2)) ax.yaxis.set_minor_locator(AutoMinorLocator(2)) 下面是使用我的代码时的外观: 这是我想要的axis样式的一个示例: 我想出了一个解决方案,可能不是最好的方法,但我使用了t

我希望将绘图上的刻度移到内部,但只移到顶部和右侧轴上。 这是我正在使用的代码

ax.tick_params(top=True, right=True, which='both')

ax.xaxis.set_minor_locator(AutoMinorLocator(2))
ax.yaxis.set_minor_locator(AutoMinorLocator(2))
下面是使用我的代码时的外观:

这是我想要的axis样式的一个示例:


我想出了一个解决方案,可能不是最好的方法,但我使用了twinx和twiny

我用这个替换了上面的代码,删除了tick_参数的初始使用


我想出了一个解决方案,可能不是最好的方法,但我使用了twinx和twiny

我用这个替换了上面的代码,删除了tick_参数的初始使用

ax.xaxis.set_minor_locator(AutoMinorLocator(2))
ax.yaxis.set_minor_locator(AutoMinorLocator(2))

ax2 = plt.twinx()
ax2.yaxis.set_minor_locator(AutoMinorLocator(2))
ax2.tick_params(which='both', direction='in')
ax2.yaxis.set_ticklabels([])

ax3 = plt.twiny()
ax3.xaxis.set_ticklabels([])
ax3.xaxis.set_minor_locator(AutoMinorLocator(2))
ax3.tick_params(which='both', direction='in')