【问题标题】:How do I set the order of a grouped bar chart with Chartify?如何使用 Chartify 设置分组条形图的顺序?
【发布时间】:2018-11-09 17:16:14
【问题描述】:

用户如何更改下例中分组条的顺序?

ch = chartify.Chart(blank_labels=True, x_axis_type='categorical') 
ch.plot.bar(
    data_frame=quantity_by_fruit_and_country,
    categorical_columns=['fruit', 'country'],
    numeric_column='quantity')
ch.show('png')

【问题讨论】:

    标签: python data-visualization chartify


    【解决方案1】:

    条形图方法有一个categorical_order_by 参数,可用于更改顺序。按照文档中的说明,将其设置为等于 valueslabels 以按这些相应的维度排序。

    对于自定义排序,您可以将值列表传递给categorical_order_by 参数。由于条形图按二维分组,因此列表应包含元组,如下例所示:

    from itertools import product
    outside_groups = ['Apple', 'Orange', 'Banana', 'Grape']
    inner_groups = ['US', 'JP', 'BR', 'CA', 'GB']
    sort_order = list(product(outside_groups, inner_groups))
    
    # Plot the data
    ch = chartify.Chart(blank_labels=True, x_axis_type='categorical')
    ch.plot.bar(
        data_frame=quantity_by_fruit_and_country,
        categorical_columns=['fruit', 'country'],
        numeric_column='quantity',
        categorical_order_by=sort_order)
    ch.show('png')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2021-10-13
      • 2018-02-09
      • 1970-01-01
      相关资源
      最近更新 更多