久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>
                • 本文介紹了如何在分組條形圖上方顯示百分比的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  以下是 pandas 數據框和由此生成的條形圖:

                  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("受訪者對數據科學領域感興趣的百分比",fontsize= 16)plt.xticks(字體大小=14)對于 plt.gca().spines.values() 中的脊椎:脊柱.set_visible(假)plt.yticks([])

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

                  解決方案

                  嘗試將以下 for 循環添加到您的代碼中:

                  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')
                  

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

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

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造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(分發帶有已編譯動態共享庫的 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="qwawimqqmiuu" id='EUytP'><tfoot id='EUytP'></tfoot><dl id='EUytP'><fieldset id='EUytP'></fieldset></dl></div>
                            主站蜘蛛池模板: a在线免费观看 | 精品久久久久久 | 伊人影院综合 | 日韩精品免费在线观看 | 午夜精品在线观看 | 国产精品嫩草影院桃色 | 欧美成人极品 | av福利在线观看 | 国产一区二区在线免费 | 四虎永久在线视频 | 欧美日韩小视频 | 国产精品一区三区 | 日本少妇网站 | 成人精品影院 | 欧美一区二区三区不卡 | 日韩三级中文字幕 | 青青伊人网 | 国产在线中文字幕 | 午夜在线| 久久精品小视频 | 日韩不卡av| 日韩免费在线视频 | 日本a级大片 | 国产三区在线观看 | 国产黄av| 成人毛片网站 | 在线成人免费视频 | 免费高清av| 一级做a视频| 影音先锋在线观看视频 | 国产午夜免费视频 | 国产人成一区二区三区影院 | 亚洲一区视频在线 | 国产一区中文字幕 | 一级毛片免费视频 | 狠狠操夜夜操 | 一区二区三区精品 | 在线理论片 | 久久久久久久国产精品 | 亚洲一区二区在线 | 免费一级片|