【问题标题】:Get values from a histogram without using plt不使用 plt 从直方图中获取值
【发布时间】:2017-12-10 23:06:58
【问题描述】:

有没有办法在不绘制图表的情况下获得直方图“x”和“y”中的值**?我在我的代码中多次(在每个循环中)使用下面的函数,我注意到我的代码在每个循环中变得越来越慢。

** 我不确定它在内部的作用是否是绘图,但我知道我的代码中的缓慢与函数“plt.hist”有关,尽管使用了 plt.close()。谢谢。

# a is a list
def function_hist(a, ini, final):

    # 12 bins
    bins = np.linspace(ini, final, 13)
    weightsa = np.ones_like(a)/float(len(a))
    y, x, _ = plt.hist(a, bins, weights = weightsa)
    plt.close()

【问题讨论】:

标签: python histogram


【解决方案1】:

使用numpy.histogram

你可以修改你的功能如下

# a is a list
def function_hist(a, ini, final):

    # 12 bins
    bins = np.linspace(ini, final, 13)
    weightsa = np.ones_like(a)/float(len(a))
    hist = np.histogram(np.array(a), bins, weights = weightsa)

【讨论】:

    猜你喜欢
    • 2016-06-20
    • 2014-05-03
    • 2012-07-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 2014-01-07
    相关资源
    最近更新 更多