[英]How to plot a histogram in python?
I am plotting a histogram with this data. 我正在使用此数据绘制直方图。
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])
This is my code: 这是我的代码:
print(len(new_dictonary.values()))
plt.figure(figsize=(15, 5))
plt.hist(new_dictonary.values())
plt.show()
I expect to have 12 bar, but I got only two bars. 我希望有12个酒吧,但我只有两个酒吧。 I have to use
plt.hist
我必须使用
plt.hist
How could correct my code to have the right picture? 如何纠正我的代码以显示正确的图片?
Edited answer: The problem is that your values are very small in magnitude and 11 out of 12 are very close to each other and the remaining one is far away. 编辑答案:问题是您的值的数量级很小,而12个值中的11个彼此非常接近,而其余的值则相距甚远。 So to have each value plotted individually as a separate bar, you need a large number of bins.
因此,要使每个值分别绘制为单独的条形,则需要大量的分箱。 Now if you limit your x-axis to show the 11 similar values out of 12, you will see that having
bins=1000
(a large number) shows 11 bars. 现在,如果将x轴限制为显示12个值中的11个相似值,则将看到
bins=1000
(大量)显示11条。
plt.hist(new_dictonary, bins=1000, edgecolor='k')
plt.xlim(0.8e-16, 1e-16)
If you show them all, you will see how far they are. 如果全部显示,您将看到它们有多远。 I don't know how you plan to fit a distribution to such data.
我不知道您打算如何使分布适合这些数据。
plt.hist(new_dictonary, bins=1000, edgecolor='k')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.