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.
Este exercício faz parte do curso
Interactive Data Visualization with Bokeh
Instruções do exercício
- 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.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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)