[Python] altair mark_area() with unexpected behaviour of y2

Discussão em 'Python' iniciado por Stack, Agosto 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make an area chart of a CDF plot (which should be always increasing), instead I get the result in the image below.

    import altair as alt
    import polars as pl

    _data = pl.DataFrame({"outcomes": [16950, 17050, 18750, 18750, 20950]})
    (
    alt.Chart(
    _data,
    )
    .transform_quantile("outcomes", step=0.1)
    .mark_area(line=True, opacity=0.5)
    .encode(
    alt.X("value:Q"),
    alt.Y("prob:Q").title("Prob"),
    # alt.Y2(alt.datum(0))
    # y2=alt.datum(0),
    )
    )


    (I can't post images because I have <10 reputation, so I leave a link instead)

    error1

    If I uncomment the alt.Y2(...) line I still don't get what I'm looking for (namely, there's no area being plotted, although it's at least the actual CDF).

    error2

    When I use the last formulation y2=alt.datum(0) it does work.

    Questions

    1. I expected Y2 to be 0 by default (I recall having read it somewhere but I cannot find it not, maybe I made it up?). It does seem to be so most of the time, when is it not? Why?
    2. I expected the alt.Y2(...) API to behave exactly the same as y2=... but it does not seem to be the case (I've had problems with this in other plots involving different channels too). When are they different? Why? Or am I doing something wrong?

    Regards.

    Versions

    • altair==5.5.0
    • polars==1.30.0

    Continue reading...

Compartilhe esta Página