简体   繁体   English

熊猫DataFrame上的条形图

[英]bar chart over pandas DataFrame

I have dataframe like this: 我有这样的数据框:

     Continent        Surplus1980  Surplus1985     ...       Surplus2005  Surplus2010

       Africa         -711.186834  -894.362995     ...      -1001.189049  -960.203280
       Asia          -1464.995609 -1528.688190     ...      -1511.834129 -1529.459409
       Europe          716.832130   580.341819     ...        574.808741   590.688746
       North America  1586.628358  2559.054466     ...       2851.819722  2867.880633
       Oceania        4163.456825  3899.532718     ...       3807.652781  3796.396563
       South America  1455.955084  1196.506188     ...       1086.940969  1093.484142

Now I want to plot a bar-chart that shows each continent value from 1980 to 2010 in the x-axis. 现在,我想绘制一个条形图,在x轴上显示1980年至2010年每个大陆的价值。 I am using this function: 我正在使用此功能:

df.plot(kind="bar", rot=0, ax=ax, width=0.5)  

my result shows me: 我的结果告诉我:
bar-chart 柱形图

So how I can change to have continent name in the legend and for each year shows me the value of each continent? 那么,如何在图例中更改大陆名称,并每年向我展示每个大陆的价值?

Use: 采用:

df.set_index('Continent').T.plot(kind='bar', rot=0, width=0.5, figsize=(10,8))

Output: 输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM