2014-06-11 12 views

Odpowiedz

8

Brak wartości wyjściowej z .plot(kind='kde'), zwraca obiekt axes.

Wartości surowce mogą być dostępne przez _x i _y metody obiektu matplotlib.lines.Line2D w działce

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

! dokładnie to, czego szukałem. 'ax.get_children()' właśnie zmieniło grę dla mnie. Nie wiedziałem, że możesz to zrobić. –

+0

Doświadczyłem kolejności zmieniających się dzieci. Czy możesz zadzwonić do nich po imieniu/konkretnie? –

5

Można również bezpośrednio wywołać funkcję scipy.stats.gaussian_kde(), że to, co dzieje się w kodzie źródłowym pandy:

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

Dokumentacja do funkcji jest dostępna:

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

+0

Od tego momentu odpowiedni kod Pandas został przeniesiony na https://github.com/pandas-dev/pandas/blob/0.21.x/pandas/plotting/_core.py#L1381-L1430 – shadowtalker

Powiązane problemy