gpt4 book ai didi

python - 绘制存储在 panda 数据框中已排序的直方图数据

转载 作者:行者123 更新时间:2023-11-30 22:04:25 27 4
gpt4 key购买 nike

我有一个 .csv 文件,其中包含直方图数据,已进行分箱和标准化,我将其读入 panda 数据帧 df:

Freq
0.4
0.0
0.0
0.0
0.01
0.05
0.1
0.04
0.05
0.05
0.02
0.08
0.10
0.03
0.07

我想使用 matplotlib 将其绘制在累积分布直方图中,但 pyplot.hist 对数据进行排序并再次对其进行分类 - 这不是我想要的。

plt.hist(df.loc[(data_tor['Freq'], cumulative = True)

谁能告诉我该怎么做?

最佳答案

您可以使用:

df['Freq'].cumsum().plot(drawstyle='steps')

enter image description here

并填充曲线下方:

ax = df['Freq'].cumsum().plot(drawstyle='steps')
ax.fill_between(df.index, 0, df['Freq'].cumsum(), step="pre")

enter image description here

关于python - 绘制存储在 panda 数据框中已排序的直方图数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53297905/

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