简体   繁体   English

matplotlib中刻度线的方向

[英]Direction of tick marks in matplotlib

有没有办法让xaxis点底部的刻度线方向向外,但顶部的方向指向内部,使用matplotlib?

Yes! 是! You can use the set_tick_params() method to do this. 您可以使用set_tick_params()方法执行此操作。 Here's an example for setting up a histogram to work as you described: 以下是设置直方图的示例,如您所述:

hist.xaxis.set_ticks_position('both')  # Adding ticks to both top and bottom
hist.xaxis.set_tick_params(direction='in', which='top')  # The bottom will maintain the default of 'out'

You can change the ascending/descending order of tick marks by passing in limits for the x and y-axes that decrease. 您可以通过传入减小的x和y轴的限制来更改刻度线的升序/降序。

IE to make the x-axis go from 10 to 0, instead of 0 to 10 and the y-axis to go from 10 to -10, you can do: IE使x轴从10变为0,而不是0到10而y轴从10变为-10,你可以这样做:

plt.xlim(10, 0)
plt.ylim(10, -10)

Here is an example from matplotlib demonstrating this functionality on a simple case. 下面是一个例子 ,从matplotlib展示在一个简单的情况下,这功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM