MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Interactive Data Visualization with Bokeh

Lihat Kursus

Petunjuk latihan

  • Create start_data by subsetting netflix for the row where "date" equals start_date.
  • Repeat for end_data to get the close value from end_date.
  • Create polygon, fill in "green", with 0.4 transparency, and finish the xs and ys arguments.
  • Add polygon to the figure's layout.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode