有没有办法在不绘制**的情况下获取直方图的“x”和“y”中的值?我在我的代码中多次(在每个循环中)使用下面的函数,我注意到我的代码在每个循环中变得越来越慢。
** 我不确定它在内部所做的是否是绘制图形,但我知道尽管使用了 plt.close(),但我的代码中的缓慢与函数“plt.hist”有关。谢谢你。
# 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()
Run Code Online (Sandbox Code Playgroud)
您可以修改您的功能如下
# 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6830 次 |
| 最近记录: |