如何在 Matplotlib 中禁用对数图的小刻度? [英] How to disable the minor ticks of log-plot in Matplotlib?
本文介绍了如何在 Matplotlib 中禁用对数图的小刻度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个简单的情节:
1) 如何禁用滴答声?2)如何减少他们的数量?
1) How to disable the ticks? 2) How to reduce their number?
这是一个示例代码:
from pylab import *
import numpy as np
x = [5e-05, 5e-06, 5e-07, 5e-08, 5e-09, 5e-10]
y = [-13, 14, 100, 120, 105, 93]
def myfunc(x,p):
sl,yt,yb,ec=p
y = yb + (yt-yb)/(1+np.power(10, sl*(np.log10(x)-np.log10(ec))))
return y
xp = np.power(10, np.linspace(np.log10(min(x)/10), np.log10(max(x)*10), 100))
pxp=myfunc(xp, [1,100,0,1e-6])
subplot(111,axisbg="#dfdfdf")
plt.plot(x, y, '.', xp, pxp, 'g-', linewidth=1)
plt.xscale('log')
plt.grid(True,ls="-", linewidth=0.4, color="#ffffff", alpha=0.5)
plt.draw()
plt.show()
产生:
推荐答案
plt.minorticks_off()
关掉它们!
要更改它们的数量/定位它们,您可以使用 subsx
参数.像这样:
To change the number of them/position them, you can use the subsx
parameter. like this:
plt.xscale('log', subsx=[2, 3, 4, 5, 6, 7, 8, 9])
来自文档:
subsx/subsy:在每个主要刻度之间放置子刻度的位置.应该是一个整数序列.例如,在 log10 尺度中:[2,3, 4, 5, 6, 7, 8, 9]
subsx/subsy: Where to place the subticks between each major tick. Should be a sequence of integers. For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9]
将在每个大调之间放置 8 个以对数间隔的小刻度打勾.
will place 8 logarithmically spaced minor ticks between each major tick.
这篇关于如何在 Matplotlib 中禁用对数图的小刻度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文