对数坐标轴中控制刻度间距

3

当我提交申请时:

ax.set_yscale('log')

对于matplotlib中的轴,它会在每个10的倍数处生成一个刻度线。有时候这会太多了,比如下面的截图所示: enter image description here 相反地,我希望在保持对数缩放的同时,每隔100或1000个倍数就能有一个刻度线。
如何在matplotlib中实现呢?
1个回答

4
只需使用matplotlib.ticker.LogLocator。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import LogLocator
x = np.linspace(0, 10, 10)
y = 2**x
f = plt.figure()
ax = f.add_subplot(111)
plt.yscale('log')
ax.yaxis.set_major_locator(LogLocator(base=100))
ax.plot(x, y)
plt.show()

在此输入图片描述 如果您愿意,可以使用相同的小定位器,或者以任何您喜欢的方式进行调整。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接