2017-12-10 4 views
0

ヒストグラムの "x"と "y"の値をグラフ化しないで**取得する方法はありますか?以下の関数をコード内で何度も(各ループ内で)使用していますが、私のコードが各ループで遅くなり、遅くなることに気付きました。pltを使用せずにヒストグラムから値を取得

**内部的にグラフ化するのはわかりませんが、私のコードの遅さは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() 
+2

以下https://stackoverflow.com/questions/17348548/any-way-to-create-histogram-with- matplotlib-plplot-without-histograma – Pavel

+0

[ヒストグラムをプロットせずにmatplotlib.pyplotでヒストグラムを作成する方法はありますか?](https://stackoverflow.com/questions/17348548/anyway-to-作成 - histogram-with-matplotlib-pyplot-without-plotting-the-histogra) – jszakmeister

答えて

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) 
関連する問題