Get startedGet started for free

High to low prices by region

Now you know how to sort a DataFrame, the estate agents have asked you to create a bar plot visualizing the average property price by region from largest to smallest.

regions has been created by grouping melb by region and calculating the average price, and preloaded for you:

regions = melb.groupby("region", as_index=False)["price"].mean()

This exercise is part of the course

Interactive Data Visualization with Bokeh

View Course

Exercise instructions

  • Sort regions by price in descending order.
  • Create the figure, setting x_range equal to the "region" column of regions and labeling the x- and y-axes as "Region" and "Sales", respectively.
  • Add bar glyphs from regions, showing the price on the y-axis against each region on the x-axis, and setting the width to 0.9
  • Update the y-axis format to display in millions of dollars with 1 decimal place.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Sort df by price in descending order
regions = regions.____("____", ascending=____)

# Create figure
fig = figure(x_range=____, x_axis_label=____, y_axis_label=____)

# Add bar glyphs
fig.vbar(x=____, top=____, width=____)

# Format the y-axis to numeric format
fig.____[____].____ = ____(____="$0.0a")

output_file(filename="sorted_barplot.html")
show(fig)
Edit and Run Code