【问题标题】:Using the output of numpy.histogram how to plot a simple curve plot?使用 numpy.histogram 的输出如何绘制简单的曲线图?
【发布时间】:2019-03-02 08:50:53
【问题描述】:

我想在 x 轴上绘制 b/w a 并在 y 轴上绘制概率图。

首先我使用 numpy.histogram 命令计算概率。 n 给了我概率。

n 中的术语数量取决于我选择了多少箱。

如果我选择 5 个 bin,那么当我打印 n 时将有 5 个术语。

使用这些概率值,我可以选择 y 轴值。

但我的目标是在 a 与概率之间绘制图表,而数组 a 中有 9 个项,n 中有 5 个项。

那么我如何将直方图的概率转换为简单的曲线图?

a=np.array([1,1,1,2,2,2,3,3,5])
n,bins = np.histogram(a,bins=5,density=True)
print(n)
plt.plot(?,n)
plt.xlabel("a")
plt.ylabel("probability")

【问题讨论】:

  • 我仍然不明白这个问题,但@Luis 在下面使用 bins 和 n 给出了答案。问题仍然是您想使用 a 和概率/箱来绘制什么?

标签: python numpy matplotlib


【解决方案1】:

如果我理解正确,这应该可以工作

plt.plot(bins, np.append(n[0], n))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 2015-09-10
    • 1970-01-01
    相关资源
    最近更新 更多