Customizing glyphs
The estate agents have requested a plot displaying the relationship between the year a property was built and its distance to the Central Business District (CBD), distinguishing between houses, units, and townhouses. You decide to use different colors and glyphs for each of the three property types.
Three subsets of melb
have been created and preloaded for you:
houses = melb.loc[melb["type"] == "h"]
units = melb.loc[melb["type"] == "u"]
townhouses = melb.loc[melb["type"] == "t"]
This exercise is part of the course
Interactive Data Visualization with Bokeh
Exercise instructions
- Create a figure,
fig
, setting x and y-axes labels to"Year Built"
and"Distance from CBD (km)"
, respectively. - Add purple circle glyphs to represent
houses
, plotting"year_built"
on the x-axis and"distance"
on the y-axis, and labeling the legend as"House"
. - Repeat the above, this time using red square glyphs for
units
, with the legend labeled as"Unit"
. - Repeat once more using green triangle glyphs to represent
townhouses
and setting the legend label to"Townhouse"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create figure
fig = ____
# Add circle glyphs for houses
fig.____(x=houses["____"], y=houses["____"], legend_label="____", color="____")
# Add square glyphs for units
fig.____(____=____, ____=____, ____="____", ____="____")
# Add triangle glyphs for townhouses
____
output_file(filename="year_built_vs_distance_by_property_type.html")
show(fig)