Get startedGet started for free

Adding a Div

The hedge fund is looking for the next big thing in the online retail market. They have asked you to produce a plot visualizing Amazon's stock price performance over the last few years, highlighting the dates where the price was above average for the period.

A subset of the stocks dataset has been created for you, filtering for AMZN stocks, and stored as a Bokeh source object. You will build a line plot including a Div and a BoxAnnotation, displaying using layout.

This exercise is part of the course

Interactive Data Visualization with Bokeh

View Course

Exercise instructions

  • Import layout and Div from the relevant Bokeh classes.
  • Add a title of "Amazon stock prices vs. average price over the period" to the layout.
  • Display the Bokeh layout containing the Div, followed by the figure underneath.

Hands-on interactive exercise

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

# Import modules
____
____
fig = figure(x_axis_label="Date", y_axis_label="Stock Price ($)")
fig.line(x="date", y="close", source=source, color="purple")
box = BoxAnnotation(bottom=amazon["close"].mean(), fill_color="green", fill_alpha=0.3)
fig.add_layout(box)
fig.xaxis[0].formatter = DatetimeTickFormatter(months="%b %Y")

# Create title
title = ____
output_file(filename="amazon_stocks.html")

# Display layout
____
Edit and Run Code