pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<i id='5iYwK'><tr id='5iYwK'><dt id='5iYwK'><q id='5iYwK'><span id='5iYwK'><b id='5iYwK'><form id='5iYwK'><ins id='5iYwK'></ins><ul id='5iYwK'></ul><sub id='5iYwK'></sub></form><legend id='5iYwK'></legend><bdo id='5iYwK'><pre id='5iYwK'><center id='5iYwK'></center></pre></bdo></b><th id='5iYwK'></th></span></q></dt></tr></i><div class="v3rfhvz" id='5iYwK'><tfoot id='5iYwK'></tfoot><dl id='5iYwK'><fieldset id='5iYwK'></fieldset></dl></div>
    • <bdo id='5iYwK'></bdo><ul id='5iYwK'></ul>

      <tfoot id='5iYwK'></tfoot>
    1. <legend id='5iYwK'><style id='5iYwK'><dir id='5iYwK'><q id='5iYwK'></q></dir></style></legend>

      <small id='5iYwK'></small><noframes id='5iYwK'>

      1. 如何在分組條形圖上方顯示百分比

        How to display percentage above grouped bar chart(如何在分組條形圖上方顯示百分比)
        <i id='6jLbo'><tr id='6jLbo'><dt id='6jLbo'><q id='6jLbo'><span id='6jLbo'><b id='6jLbo'><form id='6jLbo'><ins id='6jLbo'></ins><ul id='6jLbo'></ul><sub id='6jLbo'></sub></form><legend id='6jLbo'></legend><bdo id='6jLbo'><pre id='6jLbo'><center id='6jLbo'></center></pre></bdo></b><th id='6jLbo'></th></span></q></dt></tr></i><div class="7bttv1v" id='6jLbo'><tfoot id='6jLbo'></tfoot><dl id='6jLbo'><fieldset id='6jLbo'></fieldset></dl></div>
      2. <small id='6jLbo'></small><noframes id='6jLbo'>

        <tfoot id='6jLbo'></tfoot>

      3. <legend id='6jLbo'><style id='6jLbo'><dir id='6jLbo'><q id='6jLbo'></q></dir></style></legend>

          <tbody id='6jLbo'></tbody>

                • <bdo id='6jLbo'></bdo><ul id='6jLbo'></ul>
                • 本文介紹了如何在分組條形圖上方顯示百分比的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  以下是 pandas 數(shù)據(jù)框和由此生成的條形圖:

                  colors_list = ['#5cb85c','#5bc0de','#d9534f']result.plot(kind='bar',figsize=(15,4),width = 0.8,color = colors_list,edgecolor=None)plt.legend(labels=result.columns,fontsize=14)plt.title("受訪者對數(shù)據(jù)科學(xué)領(lǐng)域感興趣的百分比",fontsize= 16)plt.xticks(字體大小=14)對于 plt.gca().spines.values() 中的脊椎:脊柱.set_visible(假)plt.yticks([])

                  我需要在相應(yīng)欄上方顯示各個(gè)主題的每個(gè)興趣類別的百分比.我可以創(chuàng)建一個(gè)包含百分比的列表,但我不明白如何將它添加到相應(yīng)欄的頂部.

                  解決方案

                  嘗試將以下 for 循環(huán)添加到您的代碼中:

                  ax = result.plot(kind='bar', figsize=(15,4), width=0.8, color=colors_list, edgecolor=None)對于 ax.patches 中的 p:寬度 = p.get_width()高度 = p.get_height()x, y = p.get_xy()ax.annotate(f'{height}', (x + width/2, y + height*1.02), ha='center')


                  說明

                  通常,您使用

                  The following are the pandas dataframe and the bar chart generated from it:

                  colors_list = ['#5cb85c','#5bc0de','#d9534f']
                  result.plot(kind='bar',figsize=(15,4),width = 0.8,color = colors_list,edgecolor=None)
                  plt.legend(labels=result.columns,fontsize= 14)
                  plt.title("Percentage of Respondents' Interest in Data Science Areas",fontsize= 16)
                  
                  plt.xticks(fontsize=14)
                  for spine in plt.gca().spines.values():
                      spine.set_visible(False)
                  plt.yticks([])
                  

                  I need to display the percentages of each interest category for the respective subject above their corresponding bar. I can create a list with the percentages, but I don't understand how to add it on top of the corresponding bar.

                  解決方案

                  Try adding the following for loop to your code:

                  ax = result.plot(kind='bar', figsize=(15,4), width=0.8, color=colors_list, edgecolor=None)
                  
                  for p in ax.patches:
                      width = p.get_width()
                      height = p.get_height()
                      x, y = p.get_xy() 
                      ax.annotate(f'{height}', (x + width/2, y + height*1.02), ha='center')
                  


                  Explanation

                  In general, you use Axes.annotate to add annotations to your plots.
                  This method takes the text value of the annotation and the xy coords on which to place the annotation.

                  In a barplot, each "bar" is represented by a patch.Rectangle and each of these rectangles has the attributes width, height and the xy coords of the lower left corner of the rectangle, all of which can be obtained with the methods patch.get_width, patch.get_height and patch.get_xy respectively.

                  Putting this all together, the solution is to loop through each patch in your Axes, and set the annotation text to be the height of that patch, with an appropriate xy position that's just above the centre of the patch - calculated from it's height, width and xy coords.


                  For your specific need to annotate with the percentages, I would first normalize your DataFrame and plot that instead.

                  colors_list = ['#5cb85c','#5bc0de','#d9534f']
                  
                  # Normalize result
                  result_pct = result.div(result.sum(1), axis=0)
                  
                  ax = result_pct.plot(kind='bar',figsize=(15,4),width = 0.8,color = colors_list,edgecolor=None)
                  plt.legend(labels=result.columns,fontsize= 14)
                  plt.title("Percentage of Respondents' Interest in Data Science Areas",fontsize= 16)
                  
                  plt.xticks(fontsize=14)
                  for spine in plt.gca().spines.values():
                      spine.set_visible(False)
                  plt.yticks([])
                  
                  # Add this loop to add the annotations
                  for p in ax.patches:
                      width = p.get_width()
                      height = p.get_height()
                      x, y = p.get_xy() 
                      ax.annotate(f'{height:.0%}', (x + width/2, y + height*1.02), ha='center')
                  

                  這篇關(guān)于如何在分組條形圖上方顯示百分比的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個(gè)模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點(diǎn)包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復(fù)導(dǎo)入頂級(jí)名稱的情況下構(gòu)造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發(fā)帶有已編譯動(dòng)態(tài)共享庫的 Python 包)

                      • <tfoot id='EUytP'></tfoot>

                            <bdo id='EUytP'></bdo><ul id='EUytP'></ul>
                              <tbody id='EUytP'></tbody>
                            <legend id='EUytP'><style id='EUytP'><dir id='EUytP'><q id='EUytP'></q></dir></style></legend>

                            <small id='EUytP'></small><noframes id='EUytP'>

                            <i id='EUytP'><tr id='EUytP'><dt id='EUytP'><q id='EUytP'><span id='EUytP'><b id='EUytP'><form id='EUytP'><ins id='EUytP'></ins><ul id='EUytP'></ul><sub id='EUytP'></sub></form><legend id='EUytP'></legend><bdo id='EUytP'><pre id='EUytP'><center id='EUytP'></center></pre></bdo></b><th id='EUytP'></th></span></q></dt></tr></i><div class="d99r7r9" id='EUytP'><tfoot id='EUytP'></tfoot><dl id='EUytP'><fieldset id='EUytP'></fieldset></dl></div>
                            主站蜘蛛池模板: 吉林污水处理公司,长春工业污水处理设备,净水设备-长春易洁环保科技有限公司 | 耐高温硅酸铝板-硅酸铝棉保温施工|亿欧建设工程 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 原色会计-合肥注册公司_合肥代理记账公司_营业执照代办 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 大通天成企业资质代办_承装修试电力设施许可证_增值电信业务经营许可证_无人机运营合格证_广播电视节目制作许可证 | 机械加工_绞车配件_立式离心机_减速机-洛阳三永机械厂 | 中红外QCL激光器-其他连续-半导体连续激光器-筱晓光子 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 公交驾校-北京公交驾校欢迎您! 工作心得_读书心得_学习心得_找心得体会范文就上学道文库 | 隧道风机_DWEX边墙风机_SDS射流风机-绍兴市上虞科瑞风机有限公司 | BHK汞灯-百科|上海熙浩实业有限公司 | 真空泵维修保养,普发,阿尔卡特,荏原,卡西亚玛,莱宝,爱德华干式螺杆真空泵维修-东莞比其尔真空机电设备有限公司 | 硬度计,金相磨抛机_厂家-莱州华煜众信试验仪器有限公司 | VOC检测仪-甲醛检测仪-气体报警器-气体检测仪厂家-深恒安科技有限公司 | 泰安办公家具-泰安派格办公用品有限公司 | 电机铸铝配件_汽车压铸铝合金件_发动机压铸件_青岛颖圣赫机械有限公司 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 客服外包专业服务商_客服外包中心_网萌科技 | 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 播音主持培训-中影人教育播音主持学苑「官网」-中国艺考界的贵族学校 | 有声小说,听书,听小说资源库-听世界网 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 等离子表面处理机-等离子表面活化机-真空等离子清洗机-深圳市东信高科自动化设备有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | Honsberg流量计-Greisinger真空表-气压计-上海欧臻机电设备有限公司 | 刹车盘机床-刹车盘生产线-龙口亨嘉智能装备 | 焊接减速机箱体,减速机箱体加工-淄博博山泽坤机械厂 | 驾驶人在线_专业学车门户网站 | 仓储笼_仓储货架_南京货架_仓储货架厂家_南京货架价格低-南京一品仓储设备制造公司 | 英超直播_英超免费在线高清直播_英超视频在线观看无插件-24直播网 | 螺旋叶片_螺旋叶片成型机_绞龙叶片_莱州源泽机械制造有限公司 | 热回收盐水机组-反应釜冷水机组-高低温冷水机组-北京蓝海神骏科技有限公司 | 食药成分检测_调料配方还原_洗涤剂化学成分分析_饲料_百检信息科技有限公司 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 陕西安玻璃自动感应门-自动重叠门-磁悬浮平开门厂家【捷申达门业】 |