簡體   English   中英

無法 plot 直方圖(hist2d)

[英]unable to plot histogram(hist2d)

嘗試 plot 對象長度與使用 hist2d 的對象總數。 我收到以下錯誤。 你能幫我找出錯誤嗎?

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

我相信您代碼中的問題是使用hist2d而不是古老的hist 使用hist ,您不必傳遞項目數 - 它從系列中獲取:

plt.hist(length, bins = 10)
plt.xlabel('count')
plt.ylabel('length')
plt.grid(True)
plt.show()

結果(對於少量數據)是:

在此處輸入圖像描述

另一方面,如果您要查找條形圖,請按照以下方法查找length

fig, ax = plt.subplots()
ax.bar(length.index, length)
fig.show()

結果(當然,對於有限的數據)是:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM