【发布时间】:2021-03-27 23:46:14
【问题描述】:
我最近开始学习 Python 课程,我们需要绘制直方图,然后检索生成的 bin。代码如下:
fig, axs = plt.subplots(1, 1,
figsize =(10, 5),
tight_layout = True)
axs.hist(diferencia[14329:27006], bins=10, rwidth = 0.8)
plt.show()
print("\n")
plt.savefig("histograma.png")
直方图生成得很好,但我无法从中获取垃圾箱。抱歉这个基本问题,我只是 python 的初学者。 谢谢!
【问题讨论】:
-
您是否尝试将您设置 bins 变量的数字添加到图像中?或者您只是想提取您将 bins 变量设置为的内容?
-
你好。我需要 bin 范围的值,以便在表格中显示它们及其相应的频率。
-
我相信我需要看看
diferencia[14329:27006]是如何生成的以帮助您解决这个问题。或者至少看到print(diferencia[14329:27006])的结果。 -
diferencia[14329:27006]是一个带有双精度数的数组,问题是在我做直方图时生成了 bin,而不是以前生成的。因此,要获得这些垃圾箱,我必须在执行axs.hist(diferencia[14329:27006], bins=10, rwidth = 0.8)时首先创建它们。我的问题取决于我如何获得这些生成的垃圾箱。 -
这个!非常感谢@johanC,正是我需要的:)
标签: python matplotlib histogram