相关疑难解决方法(0)

如何在 0 和平均值的 y 值之间的 distplot 上绘制平均线?

我有一个 distplot,我想绘制一条从 0 到平均频率的 y 值的平均线。我想这样做,但是当 distplot 执行时让该行停止。为什么没有一个简单的参数来做到这一点?这将非常有用。

我有一些代码可以让我几乎到达那里:

plt.plot([x.mean(),x.mean()], [0, *what here?*])

Run Code Online (Sandbox Code Playgroud)

这段代码按照我想要的方式绘制了一条线,除了我想要的 y 值。使 y 最大值停止在 distplot 中的均值频率处的正确数学方法是什么?下面是我的一个 distplots 的示例,使用 0.6 作为 y-max。如果有一些数学方法可以让它停在均值的 y 值处,那就太棒了。我试过将平均值除以计数等。

在此处输入图片说明

python distribution matplotlib seaborn

5
推荐指数
1
解决办法
4276
查看次数

模拟已弃用的seaborn distplots

Seaborndistplot现已弃用,并将在未来版本中删除。建议使用histplot(或displot作为图形级图)作为替代方案。distplot但和之间的预设有所不同histplot

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns

x_list = [1, 2, 3, 4, 6, 7, 9, 9, 9, 10]
df = pd.DataFrame({"X": x_list, "Y": range(len(x_list))})

f, (ax_dist, ax_hist) = plt.subplots(2, sharex=True)

sns.distplot(df["X"], ax=ax_dist)
ax_dist.set_title("old distplot")
sns.histplot(data=df, x="X", ax=ax_hist)
ax_hist.set_title("new histplot")

plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

那么,我们如何配置histplot来复制已弃用的输出distplot

python matplotlib histogram kernel-density seaborn

4
推荐指数
1
解决办法
3261
查看次数