Spaces:
Running on Zero
Running on Zero
Download src/data/archive/statsapi/visualization/evaluation_winStreak_plot.py from jjerlee/rinklytics: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/jjerlee/rinklytics/resolve/main/src/data/archive/statsapi/visualization/evaluation_winStreak_plot.py
- Command line
-
hf download hf://spaces/jjerlee/rinklytics/src/data/archive/statsapi/visualization/evaluation_winStreak_plot.py
-
curl -L -o evaluation_winStreak_plot.py https://huggingface.co/spaces/jjerlee/rinklytics/resolve/main/src/data/archive/statsapi/visualization/evaluation_winStreak_plot.py
1.44 kB
| # sub process to evaluate win streak by season | |
| # For plotting, only look at top 15 teams | |
| dfplot = dfteams.sort_values(by = 'idx_WinStreak', ascending = False).head(15) | |
| dfplot = dfplot[['idx_WinStreak', 'idx_WinStreak_expected', | |
| 'idx_HotStreak', 'ratio', 'ratio_viz']] | |
| fig, ax = plt.subplots(figsize = (12,7)) | |
| def addlabels(x,y,z): | |
| for i in range(len(x)): | |
| plt.text(i, y[i], z[i], ha = 'center', fontsize = 12) | |
| ax.bar(dfplot.index, height = dfplot['idx_WinStreak'], \ | |
| label = "Win Streak", color = '#FFCB05') | |
| temp_plot = dfplot[dfplot.idx_WinStreak == dfplot.idx_WinStreak_expected] | |
| ax.plot(temp_plot.index, temp_plot['idx_WinStreak_expected'], \ | |
| 'v', markersize=12, c = '#00274C', label = 'Win Streak: All expected (Season RPI)') | |
| temp_plot = dfplot[dfplot.idx_WinStreak != dfplot.idx_WinStreak_expected] | |
| ax.plot(temp_plot.index, temp_plot['idx_WinStreak_expected'], \ | |
| '^', markersize=12, c = 'green', label = 'Win Streak: with unexpected (Season RPI)') | |
| # plot hot streak | |
| ax.bar(dfplot.index, height = dfplot['idx_HotStreak'], \ | |
| label = "Hot Streak", color = '#e10600') | |
| addlabels(dfplot.index, dfplot.idx_HotStreak + 0.5, dfplot.ratio_viz) | |
| plt.ylabel('Wins point generated') | |
| plt.title(f"{iter_yr}-{iter_yr+1} Regular Season Win Streak Breakdown") | |
| ax.legend() | |
| plt.savefig(str_dirc + f"/report/Team_Win_Streaks/{iter_yr}.png", \ | |
| facecolor='white', edgecolor='white') |