[Python] Altair sorting a layered chart with mark_errorbar doesn't work

Discussão em 'Python' iniciado por Stack, Julho 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a simple layered chart and I want to sort X axis by Y value. It does work with mark_rule, but not with mark_errorbar:

    df = pl.DataFrame({
    "name": ["A", "B", "C", "D"],
    "mean": [1.2, 2.5, 0.9, 3.1],
    "ymin": [1.0, 2.2, 0.85, 2.8],
    "ymax": [1.4, 2.8, 0.95, 3.4]
    })

    bars = alt.Chart(df).mark_bar().encode(
    x=alt.X("name:N").sort("-y"),
    y=alt.Y("mean:Q")
    )

    error_bars = bars.mark_errorbar().encode(
    y="ymin:Q",
    y2="ymax:Q"
    )

    rules = bars.mark_rule().encode(
    y="ymin:Q",
    y2="ymax:Q"
    )

    # Does't sort
    bars + error_bars

    # Does sort
    bars + rules


    Why does sorting with mark_rule works, but sorting with mark_errorbar doesn't?

    Continue reading...

Compartilhe esta Página