python - MatplotLib 仅在内部的顶部和右侧轴上移动刻度
问题描述
我想将我的情节上的刻度线移到内部,但只在顶部和右侧轴上。这是我正在使用的代码
ax.tick_params(top=True, right=True, which='both')
ax.xaxis.set_minor_locator(AutoMinorLocator(2))
ax.yaxis.set_minor_locator(AutoMinorLocator(2))
这是使用我的代码的外观:
这是我想要的轴样式的示例:
解决方案
我想出了一个解决方案,可能不是最好的方法,但我使用了twinx和twiny。
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')
我用这个替换了上面的代码,删除了 tick_params 的初始使用。
推荐阅读
- python - 使用熊猫在数据框之间进行值查找?
- flutter - easy_localization 具有其他语言的键的后备值
- jasper-reports - Jasper 报告标题在新页面上
- mysql - 如何在MYSQL中创建一个存储过程,该过程在开始日期和结束日期之间获取销售的开始日期和结束日期
- java - 编写一个不能使用递归的红黑树程序插入
- android - How to edit Virtual Device? Android Studio - Java
- java - 我如何知道从 Kotlin 调用 java 方法时是否应在调用站点检查可空参数?
- python - 如何拆分熊猫中的一组相关列?
- python - 使用 Pandas 根据日期和事件状态对数据进行排序
- selenium - 使用 selenium 驱动程序并行获取多个页面