Raf*_*tos 1 python plot dataframe pandas
我有以下数据框:
frame1 = pd.DataFrame(res.items(), columns=['Region', 'Ratio'])
Region Ratio
0 Midwest 0.005669
1 Northeast 0.008920
2 North 0.006374
3 South 0.002904
4 Southeast 0.001928
Run Code Online (Sandbox Code Playgroud)
我现在想要使用带有区域名称的ylabel绘制上面数据框的(hbar),但是,我只得到y标签上的数字(0到4),如下所示:
frame1['Ratio'].plot(y=frame1['Region'], x=frame1['Ratio'], kind="barh", align='center', color='blue')
Run Code Online (Sandbox Code Playgroud)
我如何绘制每个地区的名称?提前致谢
索引将是yaxis
标签,你可以试试这个:
ax = frame1.set_index('Region').plot(kind="barh", align='center', color='blue')
Run Code Online (Sandbox Code Playgroud)