Настройка:
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