【问题标题】:Converting an array of numbers into histogram bins将数字数组转换为直方图箱
【发布时间】:2014-04-05 12:47:37
【问题描述】:

我正在使用 java 程序在直方图箱中拆分数组。现在,我想手动标记直方图箱。所以 - 我想转换一些类似序列的东西:{-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.5,1,1.5, 2,2.5,4}改成下图——

有没有办法使用任何软件来做到这一点?我在 Windows 上,基于 R、python、java 或 matlab 的东西会很棒。我目前使用 mspaint 手动完成。

【问题讨论】:

  • 如果你正确地标记了你的 x 轴,并确保条在正确的位置(即更窄的条用于更窄的 bin),你肯定不需要这样的图像吗?另外,使用绘图包,这很疯狂。 R 中的直方图:statmethods.net/graphs/density.html

标签: visualization


【解决方案1】:
【解决方案2】:

嗯,最简单的方法是(Python):

import matplotlib.pyplot as plt

d = [-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.5,1,1.5,2,2.5,4]
hist(d)

plt.show()

至于在直方图上放置特殊标签,问题已涵盖:Matplotlib - label each bin

我猜你想保持简单,所以你可以这样做:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
d = [-0.9,-0.8,-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.5,1,1.5,2,2.5,4]
counts, bins, patches = ax.hist(d)
ax.set_xticks(bins)

plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-26
    相关资源
    最近更新 更多