When I plot density distribution of my pandas Series I use
JavaScript
x
2
1
.plot(kind='kde')
2
Is it possible to get output values of this plot? If yes how to do this? I need the plotted values.
Advertisement
Answer
There are no output value from .plot(kind='kde')
, it returns a axes
object.
The raw values can be accessed by _x
and _y
method of the matplotlib.lines.Line2D
object in the plot
JavaScript
1
25
25
1
In [266]:
2
3
ser = pd.Series(np.random.randn(1000))
4
ax=ser.plot(kind='kde')
5
6
In [265]:
7
8
ax.get_children() #it is the 3nd object
9
Out[265]:
10
[<matplotlib.axis.XAxis at 0x85ea370>,
11
<matplotlib.axis.YAxis at 0x8255750>,
12
<matplotlib.lines.Line2D at 0x87a5a10>,
13
<matplotlib.text.Text at 0x8796f30>,
14
<matplotlib.text.Text at 0x87a5850>,
15
<matplotlib.text.Text at 0x87a56d0>,
16
<matplotlib.patches.Rectangle at 0x87a56f0>,
17
<matplotlib.spines.Spine at 0x85ea5d0>,
18
<matplotlib.spines.Spine at 0x85eaed0>,
19
<matplotlib.spines.Spine at 0x85eab50>,
20
<matplotlib.spines.Spine at 0x85ea3b0>]
21
In [264]:
22
#get the values
23
ax.get_children()[2]._x
24
ax.get_children()[2]._y
25