[英]unable to plot histogram(hist2d)
Trying to plot length of objects vs total count of objects using hist2d.尝试 plot 对象长度与使用 hist2d 的对象总数。 I am getting the following error.我收到以下错误。 Can you please help me in finding the error.你能帮我找出错误吗?
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
count=799.000000
plt.hist2d(length,count,bins = 10)
plt.xlabel('count')
plt.ylabel('length')
plt.grid(True)
plt.show()
print(length)
1 3.978235
2 4.740024
3 3.470375
4 3.978235
5 3.808948
...
807 5.078597
808 4.655381
809 4.232164
810 4.655381
811 3.470375
Name: length_mm, Length: 799, dtype: float64
I believe the issue in you code is the use of hist2d
rather than the good-old hist
.我相信您代码中的问题是使用hist2d
而不是古老的hist
。 With hist
, you don't have to pass the number of items - it gets that from the Series:使用hist
,您不必传递项目数 - 它从系列中获取:
plt.hist(length, bins = 10)
plt.xlabel('count')
plt.ylabel('length')
plt.grid(True)
plt.show()
The result (for a small amount of data) is:结果(对于少量数据)是:
If, on the other hand, you'd looking for a bar chart, here's the way to do it for length
:另一方面,如果您要查找条形图,请按照以下方法查找length
:
fig, ax = plt.subplots()
ax.bar(length.index, length)
fig.show()
The result (for limited data, of course) is:结果(当然,对于有限的数据)是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.