Visualizing sales by period
Now you have created your factors, it is time to build a bar plot visualizing sales per month, grouped into quarters!
grouped_melb
, a pandas DataFrame containing one row for each month, its respective quarter, and total sales for that month, has been preloaded for you. Additionally, factors
, which is a list of tuples containing each quarter and month pair, has also been preloaded.
This exercise is part of the course
Interactive Data Visualization with Bokeh
Exercise instructions
- Import
NumeralTickFormatter
andFactorRange
. - Create the figure, using
FactorRange()
andfactors
for the x-axis, and labeling the y-axis as"Sales"
. - Add bar glyphs, setting
x
asfactors
,top
as the"price"
column ofgrouped_melb
, andwidth
as0.9
. - Rotate the x-axis labels to 45 degrees.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import NumeralTickFormatter and FactorRange
from ____.____ import ____, ____
# Create figure
fig = ____(x_range=____(____), ____="____")
# Create bar glyphs
____
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0.0a")
# Rotate the x-axis labels
fig.____.____ = ____
output_file(filename="sales_by_period.html")
show(fig)