Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save databyjp/fc98c7865f48ea2be15858cee1732683 to your computer and use it in GitHub Desktop.
Save databyjp/fc98c7865f48ea2be15858cee1732683 to your computer and use it in GitHub Desktop.
thresh_days = 20
df = df.assign(legend="Other teams")
df.loc[df["TEAM_NAME"] == highlight_tm, "legend"] = f"{thresh_days}+ days ago"
df.loc[(df.days_since_game < thresh_days) & (df["TEAM_NAME"] == highlight_tm), "legend"] = f"In the last {thresh_days} days"
fig = px.scatter(df, x="DEF_RATING", y="OFF_RATING",
color="legend",
title=f"Game-by-game performances by the {highlight_tm} - '21-'22",
color_discrete_sequence=["#dddddd", color_dict[highlight_tm][0], color_dict[highlight_tm][1]],
size="inv_days_since_game",
size_max=15,
template="plotly_white",
width=1200, height=800,
labels={"OFF_RATING": "Offensive Rating (higher is better)",
"DEF_RATING": "Dffensive Rating (to the left is better)",
"legend": ""}
)
fig['data'][0]['marker']['line']['color'] = "#bbbbbb"
fig['data'][0]['marker']['opacity'] = 0.05
# Add reference lines
fig.add_hline(y=rtg_mid, line_width=1)
fig.add_vline(x=rtg_mid, line_width=1)
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment