【问题标题】:Plotting already sorted histogram data stored in a panda dataframe绘制存储在熊猫数据框中的已排序直方图数据
【发布时间】:2019-04-17 06:48:43
【问题描述】:

我有一个.csv 文件,其中包含直方图数据,已经分箱和标准化,我将其读入熊猫数据框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)

谁能告诉我怎么做?

【问题讨论】:

  • 从数据来看,使用的分箱并不明显。一旦您拥有用于创建数据框的分箱,您就可以根据分箱和数据绘制条形图。

标签: python pandas matplotlib histogram binning


【解决方案1】:

你可以使用:

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

并在曲线下填充:

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

【讨论】:

  • 太好了 - 谢谢。补充问题:你知道情节下怎么填吗?
  • @abinitio 欢迎您!使用:ax = df['Freq'].cumsum().plot(drawstyle='steps')ax.fill_between(df.index, 0, df['Freq'].cumsum(), step="pre")
  • 未来读者的注意事项:如果已使用的分箱从 -1 开始,则此答案是正确的,这是非常罕见的。
猜你喜欢
  • 1970-01-01
  • 2021-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-20
  • 1970-01-01
  • 2013-08-16
相关资源
最近更新 更多