简体   繁体   English

Altair-viz:有没有办法改变多面图表的显示顺序?

[英]Altair-viz: Is there a way to change the order that faceted charts get displayed?

I want to facet my plot by column (straight-forward enough), but the faceted sub-plots are displayed in alphabetical order and I would like them displayed in a custom order.我想按列分面我的 plot(足够直截了当),但分面子图按字母顺序显示,我希望它们按自定义顺序显示。 Using this example from the Altair website facets by species and displays the sub-plots in alphabetical order: 'setosa', 'versicolor', 'virginica'.使用 Altair 网站上的这个示例按物种分面并按字母顺序显示子图:“setosa”、“versicolor”、“virginica”。

import altair as alt
from altair.expr import datum
from vega_datasets import data
iris = data.iris.url

alt.Chart(iris).mark_point().encode(
    x='petalLength:Q',
    y='petalWidth:Q',
    color='species:N',
    column='species:N'
).properties(
    width=180,
    height=180
)

Is it possible to have this example display as: 'versicolor', 'virginica', 'setosa'?是否可以将此示例显示为:'versicolor'、'virginica'、'setosa'? Thanks.谢谢。

You can use the sort property of the column encoding.您可以使用列编码的sort属性。 For example:例如:

import altair as alt
from altair.expr import datum
from vega_datasets import data
iris = data.iris.url

alt.Chart(iris).mark_point().encode(
    x='petalLength:Q',
    y='petalWidth:Q',
    color='species:N',
    column=alt.Column('species:N', sort=['virginica', 'setosa', 'versicolor'])
).properties(
    width=180,
    height=180
)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM