ComeçarComece de graça

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.

Este exercício faz parte do curso

Interactive Data Visualization with Bokeh

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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
____
Editar e executar o código