Closed dangotbanned closed 1 month ago
Thanks! This will become even prettier once https://github.com/vega/altair/pull/3505 is in.
oh btw, you have to use underscores instead of spaces when using vega_datasets
:
import altair as alt
from vega_datasets import data
imdb_rating = alt.datum["IMDB_Rating"]
chart = (
alt.Chart(data.movies.url)
.mark_point()
.transform_filter(imdb_rating != None)
.transform_filter(
alt.FieldRangePredicate("Release_Date", [None, 2019], timeUnit="year")
)
.transform_joinaggregate(AverageRating="mean(IMDB_Rating)")
.transform_calculate(RatingDelta=imdb_rating - alt.datum.AverageRating)
.encode(
x="Release_Date:T",
y=alt.Y("RatingDelta:Q").title("Rating Delta"),
color=alt.Color("RatingDelta:Q").title("Rating Delta").scale(domainMid=0),
)
)
chart
See https://github.com/vega/altair/issues/2213 and https://github.com/vega/altair/pull/2310
oh btw, you have to use underscores instead of spaces when using
vega_datasets
:
🤦 Thanks @mattijn, I'll try that out tomorrow. Feel free to edit this if you can confirm that works before I get a chance to
Recreation of
vega-lite
example https://vega.github.io/vega-lite/examples/joinaggregate_residual_graph.htmlI noticed the last example on Vega Theme Test didn't have an
altair
equivalent. This PR will also bring us one step closer to https://github.com/vega/altair/issues/3519#issuecomment-2359179155Really like how concise the methods syntax version ended up
Note
Wasn't able to use the url from
vega_datasets.data.movies.url
for this, unsure why exactlyEdit
Fixed in docs: Use vega_datasets instead of url