matplotlib顶部底部刻度线不同 [英] matplotlib top bottom ticks different

查看:39
本文介绍了matplotlib顶部底部刻度线不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 matplotlib 图中的顶部刻度和底部刻度?有时我有隐藏数据的刻度线,我只想为受影响的那一侧设置刻度线.

Is there a way to have top ticks in and bottom tick out in matplotlib plots? Sometimes I have data hiding ticks and I would like to set ticks out only for the side that is affected.

以下代码将同时影响顶部和底部或左右两侧.

The following code will affect both top and bottom or both right and left.

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot( 111 )
ax.plot( [0, 1, 3], 'o' )
ax.tick_params( direction = 'out' )
plt.show()

推荐答案

你可以有双轴,然后你可以分别设置每一边的属性:

You can have twin axes, then you can set the properties for each side separately:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([0, 1, 3], 'o')

axR = ax.twinx()
axT = ax.twiny()

ax.tick_params(direction = 'out')
axR.tick_params(direction = 'in')

ax.tick_params(direction = 'out')
axT.tick_params(direction = 'in')

plt.show()

这篇关于matplotlib顶部底部刻度线不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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