LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Interactive Data Visualization with Bokeh

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# 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
____
Code bearbeiten und ausführen