Spaces:
Sleeping
Sleeping
Update spray_new.py
Browse files- spray_new.py +70 -72
spray_new.py
CHANGED
|
@@ -848,94 +848,94 @@ def server(input,output,session):
|
|
| 848 |
|
| 849 |
fig.subplots_adjust(left=0.01, right=0.99, top=0.98, bottom=0.02)
|
| 850 |
|
| 851 |
-
@output
|
| 852 |
-
@render.plot(alt="A histogram")
|
| 853 |
-
@reactive.event(input.go, ignore_none=False)
|
| 854 |
-
def ev_plot():
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
|
| 879 |
-
|
| 880 |
|
| 881 |
-
|
| 882 |
|
| 883 |
-
|
| 884 |
|
| 885 |
|
| 886 |
-
|
| 887 |
-
|
| 888 |
|
| 889 |
-
|
| 890 |
-
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
|
| 898 |
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
-
|
| 906 |
-
|
| 907 |
-
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
|
| 914 |
-
|
| 915 |
-
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
|
| 925 |
-
|
| 926 |
-
|
| 927 |
-
|
| 928 |
-
|
| 929 |
-
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
|
| 940 |
spray = App(ui.page_fluid(
|
| 941 |
ui.tags.base(href=base_url),
|
|
@@ -1040,8 +1040,6 @@ spray = App(ui.page_fluid(
|
|
| 1040 |
ui.nav("Damage Roll",
|
| 1041 |
ui.output_plot('roll_plot',
|
| 1042 |
width='1200px',
|
| 1043 |
-
height='1200px')),
|
| 1044 |
-
ui.nav("EV vs LA",
|
| 1045 |
-
ui.output_plot("ev_plot",height = "1000px",width="1000px")),id="my_tabs",
|
| 1046 |
)
|
| 1047 |
)),)),server)
|
|
|
|
| 848 |
|
| 849 |
fig.subplots_adjust(left=0.01, right=0.99, top=0.98, bottom=0.02)
|
| 850 |
|
| 851 |
+
# @output
|
| 852 |
+
# @render.plot(alt="A histogram")
|
| 853 |
+
# @reactive.event(input.go, ignore_none=False)
|
| 854 |
+
# def ev_plot():
|
| 855 |
+
# data_df = df_2023_bip_train[df_2023_bip_train.batter_id==int(input.batter_id())]
|
| 856 |
+
# #pitch_list = df_2023_small.pitch_type.unique()
|
| 857 |
+
# sns.set_theme(style="whitegrid", palette="pastel")
|
| 858 |
+
# fig, ax = plt.subplots(1, 1, figsize=(10, 10))
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
+
# # if input.plot_id() == 'dist':
|
| 863 |
+
# # sns.histplot(x=data_df.launch_angle,y=data_df.launch_speed,cbar=colour_palette,binwidth=(5,2.5),ax=ax,cbar_kws=dict(shrink=.75,label='Count'),binrange=(
|
| 864 |
+
# # (math.floor((min(data_df.launch_angle.dropna())/5))*5,math.ceil((max(data_df.launch_angle.dropna())/5))*5),(math.floor((min(data_df.launch_speed.dropna())/5))*5,math.ceil((max(data_df.launch_speed.dropna())/5))*5)))
|
| 865 |
|
| 866 |
+
# sns.scatterplot(x=data_df.launch_angle,y=data_df.launch_speed,color=colour_palette[1])
|
| 867 |
+
# ax.set_xlim(math.floor((min(data_df.launch_angle.dropna())/10))*10,math.ceil((max(data_df.launch_angle.dropna())/10))*10)
|
| 868 |
+
# #ticks=np.arange(revels.values.min(),revels.values.max()+1 )
|
| 869 |
+
# sns.lineplot(x=angle_ev_list_df.launch_angle,y=angle_ev_list_df.launch_speed,color=colour_palette[0])
|
| 870 |
+
# ax.vlines(x=angle_ev_list_df.launch_angle[0],ymin=angle_ev_list_df.launch_speed[0],ymax=ev_ranges[-1],color=colour_palette[0])
|
| 871 |
+
# ax.vlines(x=angle_ev_list_df.launch_angle[len(angle_ev_list_df)-1],ymin=angle_ev_list_df.launch_speed[len(angle_ev_list_df)-1],ymax=ev_ranges[-1],color=colour_palette[0])
|
| 872 |
|
| 873 |
+
# groundball = f'{sum(data_df.launch_angle.dropna()<=10)/len(data_df.launch_angle.dropna()):.1%}'
|
| 874 |
+
# linedrive = f'{sum((data_df.launch_angle.dropna()<=25) & (data_df.launch_angle.dropna()>10))/len(data_df.launch_angle.dropna()):.1%}'
|
| 875 |
+
# flyball = f'{sum((data_df.launch_angle.dropna()<=50) & (data_df.launch_angle.dropna()>25))/len(data_df.launch_angle.dropna()):.1%}'
|
| 876 |
+
# popup = f'{sum(data_df.launch_angle.dropna()>50)/len(data_df.launch_angle.dropna()):.1%}'
|
| 877 |
+
# percentages_list = [groundball,linedrive,flyball,popup]
|
| 878 |
|
| 879 |
+
# hard_hit_percent = f'{sum(data_df.launch_speed.dropna()>=95)/len(data_df.launch_speed.dropna()):.1%}'
|
| 880 |
|
| 881 |
+
# barrel_percentage = f'{data_df.barrel.dropna().sum()/len(data_df.launch_angle.dropna()):.1%}'
|
| 882 |
|
| 883 |
+
# plt.text(x=27, y=math.ceil((max(data_df.launch_speed.dropna())/5))*5+5-3, s=f'Barrel% {barrel_percentage}',ha='left',bbox=dict(facecolor='white',alpha=0.8, edgecolor=colour_palette[4], pad=5))
|
| 884 |
|
| 885 |
|
| 886 |
+
# sample_dates = np.array([math.floor((min(data_df.launch_angle.dropna())/10))*10,10,25,50])
|
| 887 |
+
# sample_text = [f'Groundball ({groundball})',f'Line Drive ({linedrive})',f'Fly Ball ({flyball})',f'Pop-up ({popup})']
|
| 888 |
|
| 889 |
+
# hard_hit_dates = [95]
|
| 890 |
+
# hard_hit_text = [f'Hard Hit% ({hard_hit_percent})']
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
+
# #sample_dates = mdates.date2num(sample_dates)
|
| 895 |
+
# plt.hlines(y=hard_hit_dates,xmin=math.floor((min(data_df.launch_angle.dropna())/10))*10, xmax=math.ceil((max(data_df.launch_angle.dropna())/10))*10, color = colour_palette[4],linestyles='--')
|
| 896 |
+
# plt.vlines(x=sample_dates, ymin=0, ymax=130, color = colour_palette[3],linestyles='--')
|
| 897 |
|
| 898 |
|
| 899 |
+
# # ax.vlines(x=10,ymin=0,ymax=ev_ranges[-1],color=colour_palette[3],linestyles='--')
|
| 900 |
+
# # ax.vlines(x=25,ymin=0,ymax=ev_ranges[-1],color=colour_palette[3],linestyles='--')
|
| 901 |
+
# # ax.vlines(x=50,ymin=0,ymax=ev_ranges[-1],color=colour_palette[3],linestyles='--')
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
+
# for i, x in enumerate(hard_hit_dates):
|
| 906 |
+
# text(math.ceil((max(data_df.launch_angle.dropna())/10))*10-2.5, x+1.25,hard_hit_text[i], rotation=0, ha='right',
|
| 907 |
+
# bbox=dict(facecolor='white',alpha=0.5, edgecolor=colour_palette[4], pad=5))
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
# for i, x in enumerate(sample_dates):
|
| 911 |
+
# text(x+0.75, (math.floor((min(data_df.launch_speed.dropna())/5))*5)+1,sample_text[i], rotation=90, verticalalignment='bottom',
|
| 912 |
+
# bbox=dict(facecolor='white',alpha=0.5, edgecolor=colour_palette[3], pad=5))
|
| 913 |
+
# #ax.vlines(x=math.floor((min(data_df.launch_angle.dropna())/10))*10+1,ymin=0,ymax=ev_ranges[-1],color=colour_palette[3],linestyles='--')
|
| 914 |
+
|
| 915 |
+
# ax.set_xlim((math.floor((min(data_df.launch_angle.dropna())/10))*10,math.ceil((max(data_df.launch_angle.dropna())/10))*10))
|
| 916 |
+
# ax.set_ylim((math.floor((min(data_df.launch_speed.dropna())/5))*5,math.ceil((max(data_df.launch_speed.dropna())/5))*5+5))
|
| 917 |
+
# # ax.set_xlim(-90,90)
|
| 918 |
+
# # ax.set_ylim(0,125)
|
| 919 |
+
# ax.set_title(f'MLB - {data_df.batter_name.unique()[0]} Launch Angle vs EV Plot', fontsize=18,fontname='Century Gothic',)
|
| 920 |
+
# #vals = ax.get_yticks()
|
| 921 |
+
# ax.set_xlabel('Launch Angle', fontsize=16,fontname='Century Gothic')
|
| 922 |
+
# ax.set_ylabel('Exit Velocity', fontsize=16,fontname='Century Gothic')
|
| 923 |
+
# ax.fill_between(angle_ev_list_df.launch_angle, 130, angle_ev_list_df.launch_speed, interpolate=True, color=colour_palette[3],alpha=0.1,label='Barrel')
|
| 924 |
+
# #fig.colorbar(plot_dist, ax=ax)
|
| 925 |
+
# #fig.colorbar(plot_dist)
|
| 926 |
+
# #fig.axes[0].invert_yaxis()
|
| 927 |
+
# ax.legend(fontsize='16',loc='upper left')
|
| 928 |
+
# fig.text(x=0.03,y=0.02,s='By: @TJStats')
|
| 929 |
+
# fig.text(x=1-0.03,y=0.02,s='Data: MLB',ha='right')
|
| 930 |
+
|
| 931 |
+
# # fig.text(x=0.25,y=0.02,s='Data: MLB',ha='right')
|
| 932 |
+
# # fig.text(x=0.25,y=0.02,s='Data: MLB',ha='right')
|
| 933 |
+
# # fig.text(x=0.25,y=0.02,s='Data: MLB',ha='right')
|
| 934 |
+
# #cbar = plt.colorbar()
|
| 935 |
+
# #fig.subplots_adjust(wspace=.02, hspace=.02)
|
| 936 |
+
# #ax.xaxis.set_major_formatter(FuncFormatter(lambda x, _: int(x)))
|
| 937 |
+
# fig.set_facecolor('white')
|
| 938 |
+
# fig.tight_layout()
|
| 939 |
|
| 940 |
spray = App(ui.page_fluid(
|
| 941 |
ui.tags.base(href=base_url),
|
|
|
|
| 1040 |
ui.nav("Damage Roll",
|
| 1041 |
ui.output_plot('roll_plot',
|
| 1042 |
width='1200px',
|
| 1043 |
+
height='1200px')),id="my_tabs",
|
|
|
|
|
|
|
| 1044 |
)
|
| 1045 |
)),)),server)
|