Annotating Netflix stock price growth
As a reminder, you previously created dates and timestamps, displayed below:
start_date = dt.datetime(2017, 6, 30)
end_date = dt.datetime(2017, 7, 27)
start_float = start_date.timestamp() * 1000
end_float = end_date.timestamp() * 1000
The final steps to display the Netflix line plot with a polygon annotation are to subset the data for the stock price, call PolyAnnotation(), and add the annotation to the figure's layout.
Diese Übung ist Teil des Kurses
<Kurs>Interactive Data Visualization with Bokeh</Kurs>Übungsanweisungen
- Create
start_databy subsettingnetflixfor the row where"date"equalsstart_date. - Repeat for
end_datato get the close value fromend_date. - Create
polygon, fill in"green", with0.4transparency, and finish thexsandysarguments. - Add
polygonto the figure's layout.
Interaktive praktische Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Create start and end data
start_data = netflix.loc[netflix["____"] == ____]["close"].values[0]
end_data = ____.____[____["____"] == ____]["close"].values[0]
# Create polygon annotation
polygon = PolyAnnotation(fill_color="____", fill_alpha=____,
xs=[start_float, ____, end_float, ____],
ys=[start_data - 10, ____ + 10, end_data + 15, ____ - 15])
# Add polygon to figure and display
fig.____(____)
output_file(filename="netflix_annotated.html")
show(fig)