2014-06-11 7 views
6

मेरी पांडा श्रृंखला की मैं साजिश घनत्व वितरण मैंपांडा के आउटपुट कैसे प्राप्त करें .plot (kind = 'kde')?

.plot(kind='kde') 

का उपयोग करते हैं यह इस साजिश के उत्पादन मूल्यों को प्राप्त करना संभव है? यदि हां यह कैसे करें? मुझे प्लॉट मूल्यों की आवश्यकता है।

उत्तर

8

.plot(kind='kde') से कोई आउटपुट मान नहीं है, यह axes ऑब्जेक्ट देता है।

कच्चे मूल्यों साजिश में matplotlib.lines.Line2D वस्तु की _x और _y विधि द्वारा पहुँचा जा सकता

In [266]: 

ser = pd.Series(np.random.randn(1000)) 
ax=ser.plot(kind='kde') 

In [265]: 

ax.get_children() #it is the 3nd object 
Out[265]: 
[<matplotlib.axis.XAxis at 0x85ea370>, 
<matplotlib.axis.YAxis at 0x8255750>, 
<matplotlib.lines.Line2D at 0x87a5a10>, 
<matplotlib.text.Text at 0x8796f30>, 
<matplotlib.text.Text at 0x87a5850>, 
<matplotlib.text.Text at 0x87a56d0>, 
<matplotlib.patches.Rectangle at 0x87a56f0>, 
<matplotlib.spines.Spine at 0x85ea5d0>, 
<matplotlib.spines.Spine at 0x85eaed0>, 
<matplotlib.spines.Spine at 0x85eab50>, 
<matplotlib.spines.Spine at 0x85ea3b0>] 
In [264]: 
#get the values 
ax.get_children()[2]._x 
ax.get_children()[2]._y 
+0

! ठीक वही जो मेरे द्वारा खोजा जा रहा था। 'ax.get_children() 'बस मेरे लिए खेल बदल गया। मुझे नहीं पता था कि आप ऐसा कर सकते हैं। –

+0

मैंने बच्चों को बदलने का आदेश अनुभव किया है। क्या आप उन्हें नाम/विशेष रूप से कॉल कर सकते हैं? –

5

तुम भी सीधे scipy.stats.gaussian_kde() समारोह कॉल कर सकते हैं, कि क्या पांडा स्रोत कोड में होता है:

https://github.com/pydata/pandas/blob/master/pandas/tools/plotting.py#L284

फ़ंक्शन के लिए दस्तावेज़ वहां है:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.gaussian_kde.html

+0

प्रासंगिक पांडस कोड तब से https://github.com/pandas-dev/pandas/blob/0.21.x/pandas/plotting/_core.py#L1381-L1430 पर ले जाया गया है – shadowtalker

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