matplotlib相对于轴的位置

use*_*133 18 matplotlib

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

tac*_*ell 33

设置主要滴答:

ax = plt.gca()
ax.get_yaxis().set_tick_params(direction='out')
ax.get_xaxis().set_tick_params(direction='out')
plt.draw()
Run Code Online (Sandbox Code Playgroud)

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

ax.get_yaxis().set_tick_params(which='both', direction='out')
ax.get_xaxis().set_tick_params(which='both', direction='out')
plt.draw()
Run Code Online (Sandbox Code Playgroud)

同时设置x和y轴:

ax = plt.gca()
ax.tick_params(direction='out')
Run Code Online (Sandbox Code Playgroud)

轴级doc和轴级doc

要相对于刻度线移动刻度标签使用pad.相比

ax.tick_params(direction='out', pad=5)
plt.draw()
Run Code Online (Sandbox Code Playgroud)

同

ax.tick_params(direction='out', pad=15)
plt.draw()
Run Code Online (Sandbox Code Playgroud)