vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.28k stars 793 forks source link

Ordering of columns in FacetChart #3481

Open liquidcarbon opened 3 months ago

liquidcarbon commented 3 months ago

What happened?

I've been trying to lay out a chart with rows and columns where some of the values are missing, and ran into the problem of sort argument to alt.Column not working as expected.

without sorting

df = pd.DataFrame({
    'row': [1,1,1,2,2],
    'column': list('ABCAB'),
    'x': [1,2,3,4,5],
    'y': [1,2,3,4,5],
})

alt.Chart(df).mark_circle().encode(
    x='x',
    y='y',
    row='row',
    column=alt.Column('column')
).properties(width=120, height=80)

image

with sorting - incorrect order

alt.Chart(df).mark_circle().encode(
    x='x',
    y='y',
    row='row',
    column=alt.Column('column', sort=list('ABC'))
).properties(width=120, height=80)

image

Why would the bottom row shift? Is it a bug?

What would you like to happen instead?

proper sorting

Which version of Altair are you using?

5.3.0

joelostblom commented 3 months ago

This looks like it could be due to the underlying Vega-Lite issue, probably this one https://github.com/vega/vega-lite/issues/8675. Feel free to add your example there if you think it is the same issue or comment here if it isn't and we can troubleshoot further here.

liquidcarbon commented 3 months ago

Thanks for your response. One common theme between the calendar example in https://github.com/vega/vega-lite/issues/8675, this toy example here, and the real thing I was trying to do:

Within the row with missing columns, the remaining values are pushed to the right. Very odd!