【问题标题】:Histogram bin size直方图 bin 大小
【发布时间】:2018-11-13 09:17:23
【问题描述】:

我有这样的代码,我想知道为什么我的两个绘制图的 bin 大小不同?

import matplotlib.pyplot as pyplot
bins=15
pyplot.rcParams["figure.figsize"] = (10,10)

#echte_Ladezeit
pyplot.hist(Y_test, bins, alpha=1, label='Y_test; orange Dateien', 
color='orange', weights = np.ones_like(Y_test)/float(len(Y_test)))
pyplot.hist(Y_train, bins, alpha=1, label='Y_train; grüne Dateien', 
color='green', weights = np.ones_like(Y_train)/float(len(Y_train)))
pyplot.title('Verteilung echte_Ladezeit')
pyplot.xlabel('echte_Ladezeit')
pyplot.ylabel('Häufigkeit [%]')
pyplot.legend(loc='upper right')
pyplot.show()

实际上橙色和绿色的标记宽度应该是一样的吧?我的代码有什么错误吗?

【问题讨论】:

    标签: python pandas histogram


    【解决方案1】:

    您的代码包含pyplot.hist(..., bins, ...),其中bins = 15。这意味着 15 个 bin 在最大值和最小值之间等距分布。两个数据集的最大值和最小值不同,因此您得到不同的 15 个 bin 集。如果您想为每个数据集获得相同宽度的 bin,那么您至少有两个选择。

    1. 标准化数据集 - 两个数据集的最大值和最小值应该相同。

    2. 将 bin 定义为序列(例如,list(range(0, 40000 + 1, 5000))),如here 所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-05
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多