gpt4 book ai didi

python - Seaborn:具有相对频率的 distplot()

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:00 26 4
gpt4 key购买 nike

我正尝试在 Seaborn 中为一个研究项目制作一些直方图。我希望 y 轴为相对频率,x 轴为 -180 到 180。这是我的一个直方图的代码:

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

df = pd.read_csv('sample.csv', index_col=0)

x = df.Angle
sns.distplot(x, kde=False);

输出: seaborn frequency plot

我不知道如何将输出转换为频率而不是计数。我尝试了多种不同类型的图表来获得频率输出,但无济于事。我也遇到过这个问题,它似乎在要求 countplot with frequencies (但有另一个功能。)我试过用它作为指南但失败了。任何帮助将不胜感激。我对这个软件和 Python 都很陌生。

我的数据如下所示,可以下载: sample data

最佳答案

sns.displot 参数允许从计数转换为频率(或密度,如 sns 所指)。它通常为 False,因此您必须使用 True 启用它。在你的情况下:

sns.distplot(x, kde=False, norm_hist=True)

然后如果你想让 x 轴从 -180 到 180,只需使用:

plt.xlim(-180,180)

来自Seaborn Docs :

norm_hist : bool, optional

If True, the histogram height shows a density rather than a count. This is implied if a KDE or fitted density is plotted.

关于python - Seaborn:具有相对频率的 distplot(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46018032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com