【问题标题】:how to stop seaborn visualisation sorting the values on the X axis of a bar chart如何停止seaborn可视化对条形图X轴上的值进行排序
【发布时间】:2015-02-03 01:28:30
【问题描述】:

我在 pandas 数据框中有一列名为 month_name,其中包含一年中的某些月份。

我尝试将这些数据作为对象和分类数据类型提供给 seaborn 可视化库。

我还尝试在将列表传递给 seaborn 库之前对其进行排序。在两个实例中,结果图看起来像(月份名称乱序:

         150           105                   _ 147_
Y-amount 100   47     ____     38    33      |    |
         50  ____     |   |  _____  ____     |    |
         0   |   |    |   |  |    | |   |    |    |
             |   |    |   |  |    | |   |    |    |
                     X-month_name
             August   July   June  October  September

如何让月份名称以正确的顺序出现

并在条形顶部显示实际精确值,如年份示例中的 here,它位于 DOT PLOT 示例上方

【问题讨论】:

    标签: python pandas visualization seaborn


    【解决方案1】:

    这是 seaborn 中新的 pd.Categorical 类型的问题,目前不支持,但计划在版本 0.6.0 中添加。请参阅此 github 问题:https://github.com/mwaskom/seaborn/issues/361

    【讨论】:

    • 在此期间是否有某种解决方法?按顺序显示月份对我来说很重要。否则它真的会影响数据的可读性。解决方法可能是 1)使用 seaborn 并忍受它,或者 2)同时使用另一个可视化库。
    • 我喜欢 seaborn factorplot 和其他一些图的 COL 参数 - 它使绘制多个维度变得如此容易,这就是为什么仅仅因为它没有分类而难以移动的原因。
    • 即使 seaborn 目前不能正确显示分类数据 --> seaborn 是否能够在条形图的条形顶部显示准确的数据值?如果是这样,如何通过因子图和其他 seaborn 图实现这一目标?
    • 我的解决方法是暂时使用 matplotlib 绘图。据我了解 pandas/seaborn 开发周期,您必须等待 0.6.0 才能获得分类顺序。糟糕,目前没有更好的解决方案。
    【解决方案2】:

    来自文档:

    {x, hue, col, row}_order : list-like, optional
        Order of levels plotted on various dimensions of the figure.
        Default is to use sorted level values.
    

    【讨论】:

      猜你喜欢
      • 2018-12-08
      • 2010-10-08
      • 2022-01-17
      • 2019-02-18
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 2023-02-02
      相关资源
      最近更新 更多