2013-10-18 10 views
10

मैं अजगर में एक हिस्टोग्राम की साजिश रचने रहा द्वारा matplotlib प्रयोग करने के लिए जानकारी प्राप्त हो रही:matplotlib हिस्टोग्राम समारोह में डिब्बे

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

में तत्वों की संख्या की तरह, एक dataframe सभी डिब्बे के लिए जानकारी है कि मुद्रित करने के लिए क्या यह संभव है हर बिन?

उत्तर

16

plt.hist की वापसी मान हैं:

रिटर्न: टपल: (एन, डिब्बे, पैच) या ([N0, n1, ...], डिब्बे, [patches0, patches1, .. ।])

तो आपको केवल वापसी मूल्यों को उचित रूप से कैप्चर करना है। उदाहरण के लिए:

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 कि लौटा दिया जाता है प्रत्येक बिन कि इस्तेमाल किया गया था के किनारों को परिभाषित करता है।

संबंधित मुद्दे