Free throw percentage by position
The agency has asked for one final plot from you. You'll use factor_cmap
to build a scatter plot visualizing free throw percentage versus average points, displaying each player position as a different color.
A source object called source
has been created from the nba
dataset and preloaded for you. The variable TOOLTIPS
, containing the name of the player, has also been created, so it can be viewed when hovering the mouse over the plot.
This exercise is part of the course
Interactive Data Visualization with Bokeh
Exercise instructions
- Import
Category10_5
andfactor_cmap
. - Create
positions
, a list containing"PG"
,"SG"
,"SF"
,"PF"
, and"C"
. - Pass
"position"
to thelegend_field
argument and complete thefill_color
argument withinfig.circle()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import modules
____
____
# Create positions
positions = ["____", "____", "____", "____", "____"]
fig = figure(x_axis_label="Free Throw Percentage", y_axis_label="Points", title="Free Throw Percentage vs. Average Points", tooltips=TOOLTIPS)
# Add circle glyphs
fig.circle(x="free_throw_perc", y="points", source=source, legend_field="____", fill_color=factor_cmap("____", palette=____, factors=____))
output_file(filename="average_points_vs_free_throw_percentage.html")
show(fig)