<bdo id='UJisV'></bdo><ul id='UJisV'></ul>

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

    <tfoot id='UJisV'></tfoot>
    1. <legend id='UJisV'><style id='UJisV'><dir id='UJisV'><q id='UJisV'></q></dir></style></legend>
      <i id='UJisV'><tr id='UJisV'><dt id='UJisV'><q id='UJisV'><span id='UJisV'><b id='UJisV'><form id='UJisV'><ins id='UJisV'></ins><ul id='UJisV'></ul><sub id='UJisV'></sub></form><legend id='UJisV'></legend><bdo id='UJisV'><pre id='UJisV'><center id='UJisV'></center></pre></bdo></b><th id='UJisV'></th></span></q></dt></tr></i><div id='UJisV'><tfoot id='UJisV'></tfoot><dl id='UJisV'><fieldset id='UJisV'></fieldset></dl></div>

        如何按升序对条形图中的条形图进行排序

        How to sort bars in a bar plot in ascending order(如何按升序对条形图中的条形图进行排序)
      1. <legend id='Q2D0f'><style id='Q2D0f'><dir id='Q2D0f'><q id='Q2D0f'></q></dir></style></legend>
            <tbody id='Q2D0f'></tbody>

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

            • <tfoot id='Q2D0f'></tfoot>
            • <i id='Q2D0f'><tr id='Q2D0f'><dt id='Q2D0f'><q id='Q2D0f'><span id='Q2D0f'><b id='Q2D0f'><form id='Q2D0f'><ins id='Q2D0f'></ins><ul id='Q2D0f'></ul><sub id='Q2D0f'></sub></form><legend id='Q2D0f'></legend><bdo id='Q2D0f'><pre id='Q2D0f'><center id='Q2D0f'></center></pre></bdo></b><th id='Q2D0f'></th></span></q></dt></tr></i><div id='Q2D0f'><tfoot id='Q2D0f'></tfoot><dl id='Q2D0f'><fieldset id='Q2D0f'></fieldset></dl></div>
                • <bdo id='Q2D0f'></bdo><ul id='Q2D0f'></ul>
                  本文介绍了如何按升序对条形图中的条形图进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用matplotlib.pyplot和海运库创建了条形图。如何根据Speed对条形图进行升序排序?我想看看左边速度最低的酒吧和右边速度最快的酒吧。

                  df =
                      Id         Speed
                      1          30
                      1          35 
                      1          31
                      2          20
                      2          25
                      3          80
                  
                  import pandas as pd
                  import matplotlib.pyplot as plt
                  import seaborn as sns
                  
                  %matplotlib inline
                  
                  result = df.groupby(["Id"])['Speed'].aggregate(np.median).reset_index()
                  
                  norm = plt.Normalize(df["Speed"].values.min(), df["Speed"].values.max())
                  colors = plt.cm.Reds(norm(df["Speed"])) 
                  
                  plt.figure(figsize=(12,8))
                  sns.barplot(x="Id", y="Speed", data=gr_vel_1, palette=colors)
                  plt.ylabel('Speed', fontsize=12)
                  plt.xlabel('Id', fontsize=12)
                  plt.xticks(rotation='vertical')
                  plt.show()
                  

                  推荐答案

                  df.groupby(['Id']).median().sort_values("Speed").plot.bar()
                  

                  聚合后使用.sort_values("Speed").sort_values('Speed', ascending=False)对数据帧进行排序。

                  编辑: 因此,您需要执行以下操作:

                  result = a.groupby(["Id"])['Speed'].median().reset_index().sort_values('Speed')
                  

                  在sns.barlot中添加顺序:

                  sns.barplot(x='Id', y="Speed", data=a, palette=colors, order=result['Id'])
                  

                  这篇关于如何按升序对条形图中的条形图进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  1. <tfoot id='Gk02o'></tfoot>
                    1. <small id='Gk02o'></small><noframes id='Gk02o'>

                      <i id='Gk02o'><tr id='Gk02o'><dt id='Gk02o'><q id='Gk02o'><span id='Gk02o'><b id='Gk02o'><form id='Gk02o'><ins id='Gk02o'></ins><ul id='Gk02o'></ul><sub id='Gk02o'></sub></form><legend id='Gk02o'></legend><bdo id='Gk02o'><pre id='Gk02o'><center id='Gk02o'></center></pre></bdo></b><th id='Gk02o'></th></span></q></dt></tr></i><div id='Gk02o'><tfoot id='Gk02o'></tfoot><dl id='Gk02o'><fieldset id='Gk02o'></fieldset></dl></div>
                      <legend id='Gk02o'><style id='Gk02o'><dir id='Gk02o'><q id='Gk02o'></q></dir></style></legend>

                          <bdo id='Gk02o'></bdo><ul id='Gk02o'></ul>

                              <tbody id='Gk02o'></tbody>