2013-10-18 2 views
10

내가 파이썬에서 히스토그램을하려하고하기 matplotlib 히스토그램 기능에 쓰레기통에 대한 정보를 얻기 :로하기 matplotlib를 사용하여

plt.hist(nparray, bins=10, label='hist') 

요소의 수처럼 모든 빈에 대한 정보를 가지고있는 dataframe를 인쇄 할 수 있나요 모든 빈? plt.hist

답변

16

반환 값은 :

결과 : 튜플 (N, 빈들, 패치) 또는 ([N0, N1, ..., 빈들 [patches0, 패치 1, .. .])

이렇게하면 반환 값을 적절하게 캡처하면됩니다. 예를 들어 반환

import numpy as np 
import matplotlib.pyplot as plt 

# generate some uniformly distributed data 
x = np.random.rand(1000) 

# create the histogram 
(n, bins, patches) = plt.hist(x, bins=10, label='hst') 

plt.show() 

# inspect the counts in each bin 
In [4]: print n 
[102 87 102 83 106 100 104 110 102 104] 

# and we see that the bins are approximately uniformly filled. 
# create a second histogram with more bins (but same input data) 
(n2, bins2, patches) = plt.hist(x, bins=20, label='hst') 

In [34]: print n2 
[54 48 39 48 51 51 37 46 49 57 50 50 52 52 59 51 58 44 58 46] 

# bins are uniformly filled but obviously with fewer in each bin. 

bins 사용 된 각 빈의 가장자리를 정의합니다.

관련 문제