【问题标题】:Histogram is displaying nothing in python直方图在 python 中不显示任何内容
【发布时间】:2020-08-19 07:16:15
【问题描述】:

我尝试了很多次,但我的直方图 id 没有显示图形,只显示轴线。这是我用来绘制直方图的代码。请帮忙!

%matplotlib inline
bins = np.linspace(0, 2, 40)
plt.figure(figsize=(20,10))
plt.hist(x_input, bins, alpha=0.5, histtype='bar')
plt.legend(['Red', 'Blue','Green'])
plt.axis([1,500,0,300])
plt.show()

【问题讨论】:

  • x_input 包含什么?你能给出输入的一些范围值吗?
  • 尝试删除plt.axis([1,500,0,300])的相同代码

标签: python matplotlib data-science


【解决方案1】:

在尝试您的代码时,问题来自plt.axis([1,500,0,300])

x_input 中的值是什么?

也许改变linspace的参数也可以解决你的问题。 因为你在 0 和 2 之间有 40 个 bin,但你的轴是 500。

【讨论】:

    【解决方案2】:

    问题在于您的垃圾箱。以下代码给出了正确的情节

      import matplotlib.pyplot as plt
      import numpy as np
      x_input=[[10,20,30,40,50,60],[10,20,30,40,50,60],[10,20,30,40,50,60]]
      bins = np.linspace(0, 2, 40)
      plt.hist(x_input,alpha=0.9)
      plt.legend(['Red', 'Blue','Green'])
      plt.axis([1,20,0,20])
      plt.show()
    

    如果问题不存在,与您尝试绘制的共享数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-11
      • 1970-01-01
      相关资源
      最近更新 更多