cha*_*ert 4 python data-visualization 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')
Run Code Online (Sandbox Code Playgroud)
条形图方法有一个categorical_order_by可用于更改顺序的参数。按照文档中的指定,将其设置为等于values或labels按相应维度排序。
对于自定义排序,您可以将值列表传递给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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
673 次 |
| 最近记录: |