在python中生成对数刻度刻度

问题描述 投票:0回答:2

我需要生成一个列表,其中包含10 ^ a和10 ^ b之间的对数刻度滴答,并且

 # List containing 0.1, 0.2, 0.3, ..., 800, 900, 1000 
 x = np.arange(0.1, 1.0, 0.1).tolist() +
     np.arange(1, 10, 1).tolist() + 
     np.arange(10, 100, 10).tolist() + 
     np.arange(100, 1000, 100).tolist()

有没有一种方法可以做到这一点?

python numpy matplotlib numpy-ndarray
2个回答
1
投票

可以用broadcasting-

broadcasting

0
投票

如果您只想对数刻度刻度,则可以使用N = 4 # number of "levels" out = ((10**np.arange(N)[:,None])*np.arange(0.1, 1.0, 0.1)).ravel()

matplotlib

输出:

x = np.arange(100) y = x**2 plt.plot(x,y) plt.xscale('log')

© www.soinside.com 2019 - 2024. All rights reserved.