-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ci-add-changelog-cats
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Calculate Residuals | ||
------------------- | ||
A dot plot showing each movie in the database, and the difference from the average movie rating. | ||
The display is sorted by year to visualize everything in sequential order. | ||
The graph is for all Movies before 2019. | ||
Adapted from `Calculate Residuals <https://vega.github.io/vega-lite/examples/joinaggregate_residual_graph.html>`_. | ||
""" | ||
# category: advanced calculations | ||
|
||
import altair as alt | ||
from vega_datasets import data | ||
|
||
imdb_rating = alt.datum["IMDB_Rating"] | ||
source = data.movies.url | ||
|
||
chart = ( | ||
alt.Chart(source) | ||
.mark_point() | ||
.transform_filter(imdb_rating != None) | ||
.transform_filter( | ||
alt.FieldRangePredicate("Release_Date", [None, 2019], timeUnit="year") | ||
) | ||
.transform_joinaggregate(Average_Rating="mean(IMDB_Rating)") | ||
.transform_calculate(Rating_Delta=imdb_rating - alt.datum.Average_Rating) | ||
.encode( | ||
x=alt.X("Release_Date:T", title="Release Date"), | ||
y=alt.Y("Rating_Delta:Q", title="Rating Delta"), | ||
color=alt.Color( | ||
"Rating_Delta:Q", | ||
title="Rating Delta", | ||
scale=alt.Scale(domainMid=0), | ||
), | ||
) | ||
) | ||
chart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Calculate Residuals | ||
------------------- | ||
A dot plot showing each movie in the database, and the difference from the average movie rating. | ||
The display is sorted by year to visualize everything in sequential order. | ||
The graph is for all Movies before 2019. | ||
Adapted from `Calculate Residuals <https://vega.github.io/vega-lite/examples/joinaggregate_residual_graph.html>`_. | ||
""" | ||
# category: advanced calculations | ||
|
||
import altair as alt | ||
from vega_datasets import data | ||
|
||
imdb_rating = alt.datum["IMDB_Rating"] | ||
source = data.movies.url | ||
|
||
chart = ( | ||
alt.Chart(source) | ||
.mark_point() | ||
.transform_filter(imdb_rating != None) | ||
.transform_filter( | ||
alt.FieldRangePredicate("Release_Date", [None, 2019], timeUnit="year") | ||
) | ||
.transform_joinaggregate(Average_Rating="mean(IMDB_Rating)") | ||
.transform_calculate(Rating_Delta=imdb_rating - alt.datum.Average_Rating) | ||
.encode( | ||
x=alt.X("Release_Date:T").title("Release Date"), | ||
y=alt.Y("Rating_Delta:Q").title("Rating Delta"), | ||
color=alt.Color("Rating_Delta:Q").title("Rating Delta").scale(domainMid=0), | ||
) | ||
) | ||
chart |