查找Dataframe.plot.kde()的x,y坐标

时间:2019-05-09 19:06:43

标签: pandas dataframe scipy

  • 我正在尝试确定kde /高斯的峰值坐标(x,y) 曲线
  • 如何从中获取 X 值和 Y 值 missing_mae.plot.kde(...)这样我就可以得到argmax()

enter image description here

losing_mae.tail(10)

238    -500.0
239    -637.5
240    -412.5
242   -1062.5
243    -562.5
245    -412.5
247    -437.5
252    -800.0
254    -662.5
255   -1062.5
Name: mae, Length: 113, dtype: float64

losing_mae.hist(ax=ax, bins=25, color='c', alpha=0.5)

losing_mae.plot.kde(color='c', ax=ax2, lw=1)

1 个答案:

答案 0 :(得分:1)

设置:

Child

import numpy as np import pandas as pd losing_mae = pd.DataFrame.from_dict({1: {0: -500.0, 1: -637.5, 2: -412.5, 3: -1062.5, 4: -562.5, 5: -412.5, 6: -437.5, 7: -800.0, 8: -662.5, 9: -1062.5}} 图返回一个axes对象。您可以向下查找x和y:

kde

给出对象列表。您可能想深入研究d = losing_mae.plot.kde() print(d.get_children())

Line2D

现在抓住该行及其[<matplotlib.lines.Line2D at 0x7fb82ce67550>, <matplotlib.spines.Spine at 0x7fb82d237e80>, <matplotlib.spines.Spine at 0x7fb84003cd30>, <matplotlib.spines.Spine at 0x7fb82d221b38>, <matplotlib.spines.Spine at 0x7fb82d221748>, <matplotlib.axis.XAxis at 0x7fb82d2590f0>, <matplotlib.axis.YAxis at 0x7fb82d221400>, Text(0.5, 1.0, ''), Text(0.0, 1.0, ''), Text(1.0, 1.0, ''), <matplotlib.legend.Legend at 0x7fb82ce67400>, <matplotlib.patches.Rectangle at 0x7fb82cea6940>] ,然后您可以得到path

vertices

分隔X和Y:

l = d.get_children()[0].get_path()
l = l.vertices
print(l)

array([[-1.38750000e+03,  5.87608940e-05],
       [-1.38619870e+03,  5.97906082e-05],
       [-1.38489740e+03,  6.08341884e-05],
       ....  # and so on for ~2000 points

然后您可以同时致电x, y = np.split(l.vertices, 2, 1) 以获得所需的积分:

max