Analyzing basketball stats
You have been contracted by a national basketball team to help them visualize and understand key player stats for their top 50 players.
They have requested you to create a plot comparing players' 'Field Goal Percentage' (FGP
) vs. their 'Points Per Game' (PPG
). This sounds like a great opportunity to utilize your scatterplot skills!
It is important that this graph is comparable to their other graphs. Therefore, all axes need to start at 0 and the y-axis (FGP
) needs to have a range of 0-100, since it is a percentage.
You have available a bball_data
DataFrame with columns FGP
and PPG
.
This exercise is part of the course
Introduction to Data Visualization with Plotly in Python
Exercise instructions
- Create a
plotly.express
scatterplot withPPG
on the x-axis andFGP
on the y-axis and show it to see the default doesn't start at zero. - Use the
update_layout()
method to change the x-axis range to be from 0 to a buffer of 5 past the maximum of thePPG
variable. - Now use the
update_layout()
method to update the range of the y-axis to be 0 to 100.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create and show the plot
fig = px.scatter(
data_frame=bball_data,
x=___,
y=___,
title='Field Goal Percentage vs. Points Per Game')
fig.show()
# Update the x_axis range
fig.update_layout({____: {'range': [____, bball_data['PPG'].max() + ____]}})
fig.show()
# Update the y_axis range
fig.update_layout({____: {'range' : [____, ____]}})
fig.show()