matplotlib滴答相对于轴的位置 [英] matplotlib ticks position relative to axis

查看:209
本文介绍了matplotlib滴答相对于轴的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

matplotlib中是否有一种方法可以设置标签和轴之间的刻度,就像在Origin中默认设置的那样?在线示例部分未显示具有此功能的单个图.我喜欢在绘图区域之外有刻度线,因为有时绘图区域在内部时会隐藏刻度线.

Is there a way in matplotlib to set ticks between the labels and the axis as it is by default in Origin? The examples section online does not show a single plot with this feature. I like having ticks outside the plotting area because sometimes the plot hides the ticks when inside.

推荐答案

要设置主要刻度线:

ax = plt.gca()
ax.get_yaxis().set_tick_params(direction='out')
ax.get_xaxis().set_tick_params(direction='out')
plt.draw()

设置所有刻度(次要和主要),

to set all ticks (minor and major),

ax.get_yaxis().set_tick_params(which='both', direction='out')
ax.get_xaxis().set_tick_params(which='both', direction='out')
plt.draw()

同时设置x和y轴:

ax = plt.gca()
ax.tick_params(direction='out')

轴级文档要相对于刻度线移动刻度线标签,请使用pad.比较

To shift the tick labels relative to the ticks use pad. Compare

ax.tick_params(direction='out', pad=5)
plt.draw()

ax.tick_params(direction='out', pad=15)
plt.draw()

这篇关于matplotlib滴答相对于轴的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆