簡體   English   中英

如何使用Chartify設置分組條形圖的順序?

[英]How do I set the order of a grouped bar chart with Chartify?

用戶如何在下面的示例中更改分組條的順序?

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

分組條形圖

條形圖方法有一個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')

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM