我有一些多面条形图,显示不同绘画中不同颜色的数量。
base = alt.Chart(df).mark_bar().encode(
x=alt.X(
'color',
title='',
),
y=alt.Y(
'amount',
title='',
),
color=alt.Color('color',scale= alt.Scale(domain=rp,range=rph))
).properties(
width=80,
height=80
).facet(
facet='TITLE',
columns=5
)
我想对每个图表按 x 轴降序排序,所以我添加:
x=alt.X(
'color',
title='',
sort='-y'
)
第二张和第五张图几乎排序正确,但不完全正确,第一张和第三张图也是如此,但由于某种原因它们正在升序。什么会导致这种奇怪的行为?和面相有关系吗?
添加 .resolve_scale(x='independent') 是否会产生所需的输出?
import altair as alt
base = (
alt.Chart(df)
.mark_bar()
.encode(
x=alt.X(
"color",
title="",
sort="-y",
),
y=alt.Y(
"amount",
title="",
),
color=alt.Color("color", scale=alt.Scale(domain=rp, range=rph)),
)
.properties(width=80, height=80)
.facet(facet="TITLE", columns=5)
.resolve_scale(x="independent")
)