Skip to content

Facet sort order not respected with more than 5000 points #572

@rben01

Description

@rben01

When the data has so many rows that vegafusion is required for Altair to produce a plot — I believe the max before vegafusion is necessary is 5000 — a custom sort order for facet columns is ignored. MRE:

import altair as alt
import numpy as np
import polars as pl
import vegafusion
from IPython.display import display

print(
    {
        "altair": alt.__version__,
        "polars": pl.__version__,
        "vegafusion": vegafusion.__version__,
    }
)

N = 5001
df = pl.DataFrame(
    {
        "person": np.random.choice(["Alice", "Bob"], N),
        "x": np.random.rand(N),
        "y": np.random.rand(N),
    }
)


with alt.data_transformers.enable("vegafusion"):
    chart = (
        alt.Chart(df)
        .mark_point()
        .encode(alt.X("x"), alt.Y("y"))
        .facet(column=alt.Column("person", sort=["Bob", "Alice"]))
    )
    _ = display(chart)

Version info: {'altair': '5.5.0', 'polars': '1.35.1', 'vegafusion': '2.0.3'}

Chart (with Alice before Bob, which is incorrect):

Image

When you decrease N to 5000 (but keep vegafusion enabled nonetheless), you get the expected behavior:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions