[英]How to plot bar chart in Python using matplotlib.pyplot ? Argument height must be 'xxxx' or scalar
我有一個名為“ train”的數據框,其中包含多個變量。 這樣的變量之一就是“工業”。 “行業”列的前10個元素如下:
train['industry'][:10]
0 Office supplies
1 Unknown
2 Misc services
3 Social services
4 Unknown
5 Manufacturing
6 Social services
7 Office supplies
8 Entertainment
9 Construction
Name: industry, dtype: object
我正在嘗試使用matplotlib.pyplot作為plt庫繪制條形圖,其中x軸為行業類型,y軸為頻率。 我不太確定'height'參數的值應該是什么?
plt.bar(train['industry'], height = )
身高就是你的頻率。 這是一個例子
制作長度為len(train.index)
數組
使您的條形圖沒有行業名稱plt.bar(array, frequency)
。 頻率/高度不能為字符串。 它必須是數字。 如果不是,請使用pd.to_numeric
轉換
將行業名稱放入數組
使用set_xticklabels(industries)
更改標簽
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.