【问题标题】:Log x-axis for histogram为直方图记录 x 轴
【发布时间】:2017-04-21 09:43:35
【问题描述】:

我正在尝试使用对数 x 轴绘制直方图。我目前使用的代码如下

plt.hist(data, bins=10 ** np.linspace(0, 1, 2, 3), normed=1) 
plt.xscale("log")

但是,x 轴实际上并没有正确绘制!它只是从1100。理想情况下,我希望为1101001000 加上刻度线。有什么想法吗?

【问题讨论】:

  • 请提供样本数据集。
  • 我的数据是一份辐射暴露量列表——让我找到这个列表。 data=[13.140,17.520,15.768,10.512,10.512,9.636,10.512, 9.636,11.388,7.884,7.008,7.008,9.636,11.388,7.884,7.88,16.644,42.924,17.520

标签: matplotlib plot histogram axis


【解决方案1】:

以下作品。

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()

在您的代码中,探针是bins 数组。它只有两个值,[1, 10],而如果你想在1,10,100,and 1000 上打勾,你需要提供这些数字为bins

【讨论】:

  • 请注意,这不适用于 density 参数,因为它使用距离而不是对数距离进行标准化
猜你喜欢
  • 1970-01-01
  • 2021-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
相关资源
最近更新 更多