我试图用对数 x Axis 绘制直方图。我目前使用的代码如下
plt.hist(data, bins=10**(np.linspace(0, 1, 2, 3), normed=1)
plt.xscale('log')
但是,x Axis 实际上并未正确绘制!它只是从 1 到 100。理想情况下,我希望有 1、10、100 和 1000 的刻度线。有什么想法吗?
最佳答案
以下作品。
import matplotlib.pyplot as plt
import numpy as np
data = [1.2, 14, 150 ]
bins = 10**(np.arange(0,4))
print "bins: ", bins
plt.xscale('log')
plt.hist(data,bins=bins)
plt.show()
在您的代码中,problem 是
bins
大批。它只有两个值,[1, 10]
, 而如果你想在 1,10,100,and 1000
打勾您需要将这些号码提供为 bins
.
关于matplotlib - 直方图的对数 x Axis ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41000668/