Created
December 22, 2018 19:30
-
-
Save jes-moore/cdf5aa6e5406e946fd36f03e30fd5e65 to your computer and use it in GitHub Desktop.
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
# Generate linear fit and chart 1 | |
slope, intercept, r_value, p_value, std_err = stats.linregress( | |
seasonal_df['rebound_ratio'], seasonal_df['win']) | |
line = slope * seasonal_df['rebound_ratio'].values + intercept | |
ch1_data = go.Scatter( | |
x=seasonal_df['rebound_ratio'].values, | |
y=seasonal_df['win'].values, | |
mode='markers', | |
marker=go.Marker(color='rgb(255, 127, 14)'), | |
name='Data') | |
ch1_fit = go.Scatter( | |
x=seasonal_df['rebound_ratio'].values, | |
y=line, | |
mode='lines', | |
marker=go.Marker(color='rgb(31, 119, 180)'), | |
name='Fit') | |
# Generate linear fit and chart 2 | |
slope, intercept, r_value, p_value, std_err = stats.linregress( | |
seasonal_df['rebound_ratio'], seasonal_df['shots']) | |
line = slope * seasonal_df['rebound_ratio'].values + intercept | |
ch2_data = go.Scatter( | |
x=seasonal_df['rebound_ratio'].values, | |
y=seasonal_df['shots'].values, | |
mode='markers', | |
marker=go.Marker(color='rgb(255, 127, 14)'), | |
name='Data', | |
xaxis='x2', | |
yaxis='y2') | |
ch2_fit = go.Scatter( | |
x=seasonal_df['rebound_ratio'].values, | |
y=line, | |
mode='lines', | |
marker=go.Marker(color='rgb(31, 119, 180)'), | |
name='Fit', | |
xaxis='x2', | |
yaxis='y2') | |
# Generate linear fit and chart 3 | |
slope, intercept, r_value, p_value, std_err = stats.linregress( | |
seasonal_df['shots'], seasonal_df['win']) | |
line = slope * seasonal_df['shots'].values + intercept | |
ch3_data = go.Scatter( | |
x=seasonal_df['shots'].values, | |
y=seasonal_df['win'].values, | |
mode='markers', | |
marker=go.Marker(color='rgb(255, 127, 14)'), | |
name='Data', | |
xaxis='x3', | |
yaxis='y3') | |
ch3_fit = go.Scatter( | |
x=seasonal_df['shots'].values, | |
y=line, | |
mode='lines', | |
marker=go.Marker(color='rgb(31, 119, 180)'), | |
name='Fit', | |
xaxis='x3', | |
yaxis='y3') | |
#Set Figure | |
fig = tools.make_subplots( | |
rows=1, | |
cols=3, | |
subplot_titles=('Rebounds Rate vs Wins', 'Rebound Rate vs Shots ', | |
'Shots vs Wins'), | |
horizontal_spacing=0.1) | |
fig.append_trace(ch1_data, 1, 1) #rebs predicting wins | |
fig.append_trace(ch1_fit, 1, 1) | |
fig.append_trace(ch2_data, 1, 2) #rebs predicting shots | |
fig.append_trace(ch2_fit, 1, 2) | |
fig.append_trace(ch3_data, 1, 3) #shots predicting wins | |
fig.append_trace(ch3_fit, 1, 3) | |
#Set Axis | |
fig['layout']['xaxis'].update(title='Ratio of Shots Leading to Rebounds') | |
fig['layout']['xaxis2'].update(title='Ratio of Shots Leading to Rebounds') | |
fig['layout']['xaxis3'].update(title='Number of Shots') | |
fig['layout']['yaxis'].update(title='Number of Wins') | |
fig['layout']['yaxis2'].update(title='Number of Shots') | |
fig['layout']['yaxis3'].update(title='Number of Wins') | |
fig['layout'].update( | |
height=400, | |
width=1000, | |
title=None, | |
showlegend=False, | |
) | |
iplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment