【问题标题】:Seaborn weighted average line for KDE plotKDE 图的 Seaborn 加权平均线
【发布时间】:2019-01-21 18:49:58
【问题描述】:

有谁知道如何将参考线图添加到代表每个 x 值的中值的 kdeplot 中。

我尝试使用带有汉明滤波器的卷积对其进行平滑处理,但效果不佳。

【问题讨论】:

  • 我觉得这个问题不是特别清楚。 numpy 数组的中位数可以通过np.median() 获得。问题是在x=np.median(data) 处绘制垂直线吗?
  • 感谢您的协助。我有一个 KDEplot(显示一些密度云)现在我想要一条代表每个 x 坐标处中位数的曲线(基本上沿着最密集的区域分割云)
  • 哦,那是 2D kdeplot?我建议你多用一句话来解释问题和期望的结果。此外,如果您提供一些代码示例,人们可能更倾向于使用它并提供答案。

标签: matplotlib seaborn line-plot


【解决方案1】:

最后,我通过绘图解决了它

# create an aggregation ef
ef = df[['Temp','Power]].groupby('Temp').median().reset_index()

# smooth the aggregation with mean() - shift(- half window) is needed for alignment
ef['roll_med_power'] = ef['Power'].rolling(5).mean().shift(-2)

# finally close the gaps at beginning and end with unsmoothed data
ef['roll_med'][:2] = ef['Power'][:2]
ef['roll_med'][-2:] = ef['Power'][-2:]

【讨论】:

    猜你喜欢
    • 2022-06-11
    • 1970-01-01
    • 2021-08-09
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2013-09-02
    相关资源
    最近更新 更多