Найти координаты x, y объекта Dataframe.plot.kde () - PullRequest
1 голос
/ 09 мая 2019
  • Я пытаюсь определить координаты пика (x, y) kde / gaussian кривая
  • Как получить значения X и Y из losing_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 Ответ

1 голос
/ 10 мая 2019

Настройка:

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}}

График kde возвращает объект axes.Вы можете детализировать, чтобы найти x и y:

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:

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:

x, y = np.split(l.vertices, 2, 1)

И тогда вы можете просто позвонить max на оба, чтобы получить нужные вам очки:

peakX, peakY = x.max(), y.max()
print(peakX, peakY)
87.5 0.0015392054229208412
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...