如何在python中绘制直方图?

时间:2019-01-27 19:26:23

标签: python matplotlib

我正在使用此数据绘制直方图。

dict_values([2.5039286220812003e-18, 8.701119009863531e-17, 9.181036322384948e-17, 8.972473923736572e-17, 9.160265320730097e-17, 8.826609291023463e-17, 8.888913336226638e-17, 8.993242948900264e-17, 9.556623462346049e-17, 8.847279448923369e-17, 8.86804710730486e-17, 8.806035948033239e-17])

这是我的代码:

print(len(new_dictonary.values()))
plt.figure(figsize=(15, 5))
plt.hist(new_dictonary.values())
plt.show()

我希望有12条,但我只有2条。我必须使用plt.hist enter image description here

如何纠正我的代码以显示正确的图片?

1 个答案:

答案 0 :(得分:2)

编辑后的答案:问题是,您的值幅值非常小,而12个值中的11个值彼此非常接近,而其余的值则相距甚远。因此,要使每个值分别绘制为单独的条形,则需要大量的分箱。现在,如果将x轴限制为显示12个值中的11个相似值,则会看到<table>(数量很大)显示11条。

bins=1000

enter image description here

如果全部显示,您将看到它们有多远。我不知道您打算如何使分布适合此类数据。

plt.hist(new_dictonary, bins=1000, edgecolor='k')
plt.xlim(0.8e-16, 1e-16)

enter image description here

相关问题