2017-12-10 5 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-histopla-plotting-the-histogra – Pavel

+0

히스토그램을 그리지 않고 matplotlib.pyplot으로 막대 그래프를 만들 수있는 방법은 무엇입니까? (https://stackoverflow.com/questions/17348548/anyway-to- 생성 - histogram-with-matplotlib-pyplot-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) 
관련 문제