python - 用频率表绘制频率分布/直方图

标签 python r matplotlib plot

我熟悉 matplotlib 直方图引用:

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.hist

但是,我实际上没有原始系列/数据可以传递到图中。我只有 DataFrame 中的摘要统计信息。示例:

df

lower  upper  occurrences  frequency
0.0    0.5    17           .111
0.5    0.1    65           .426
0.1    1.5    147          .963
1.5    2.0    210          1.376
.
.
.

最佳答案

您不想在这里计算直方图,因为您已经有了直方图数据。因此,您可以简单地绘制条形图。

fig, ax = plt.subplots()
ax.bar(df.lower, df.occurences, width=df.upper-df.lower, ec="k", align="edge")

关于python - 用频率表绘制频率分布/直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45175643/

相关文章:

R 错误 : unknown timezone with as. POSIXct()

python - 非线性颜色图,matplotlib

python - 删除 kivy 文本输入边界

python - 替换 MainWindow 中的 CentralWidget

python - 元素不可点击,因为另一个元素遮挡了它

python - 结合Matplotlib和Pandas时对fig、ax、plt的理解

python - 如何在Python Matplotlib折线图中设置所需的时间间隔和X轴的所需格式?

python - Pandas 给定日期的季度天数

r - 从字符向量中获取近似唯一的值

r - 绘制用于 Cox 回归的 Kaplan-Meier