我想用 2 個類可視化一個條形圖。Class=0 其顏色為藍色,class=1 其顏色為紅色。
#here its my code
x = ['0','1']
real = df[df['fake'] == 0].count()
fake = df[df['fake'] == 1].count()
plt.bar(x, real, color='blue')
plt.bar(x, fake, color='red')
plt.title("Class Fake & Real")
plt.show()
錯誤代碼: ValueError:形狀不匹配:無法將物件廣播到單個形狀
uj5u.com熱心網友回復:
from matplotlib import pyplot as plt
x = ['0', '1']
real, fake = 5, 10
plt.bar(x[0], real, color='blue')
plt.bar(x[1], fake, color='red')
plt.title("Class Fake & Real")
plt.show()

您的錯誤可能來自錯誤型別的realand fake。順便說一句,對于為條形配置不同的顏色,有一個更好的
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/462361.html
標籤:Python matplotlib 条形图 可视化
上一篇:pandas.errors.InvalidIndexError:(slice(None,None,None),None)
