【问题标题】:Plotting histogram for same bin size but different values in each bin [duplicate]绘制相同bin大小但每个bin中值不同的直方图[重复]
【发布时间】:2021-01-25 11:36:10
【问题描述】:

我正在绘制直方图,其中 bin 大小为 10,每个分布从 1 到 100,现在我必须绘制 y= [1852, 1111, 1110, 1111, 741, 1482, 371, 370, 371, 1110] 的这些值。 假设对于 bin 0,我有 1825,bin1 我有 1111。在 x 轴上我有 1 到 100,而在 y 轴上它达到 10000。尝试了以下代码但不起作用。 p>

y=[b0, b1,b2,b3,b4,b5,b6,b7,b8,b9]
plt.hist(y, bins=10)

【问题讨论】:

  • 看来您可能需要bar plot 来代替?
  • 我试过但没用
  • 请分享代码

标签: python matplotlib histogram


【解决方案1】:

你需要matplotlib.pyplot.bar

>> import matplotlib.pyplot as plt
>>> x = range(10, 101, 10)
>>> plt.bar(x, y, width=9, tick_label=x)
<BarContainer object of 10 artists>

输出:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多