Tech stock performance over time
The hedge fund would like to analyze trends in tech stocks over the past few years. They have asked for a line plot displaying stock prices for Apple, IBM, and Netflix.
They would also like a DateRangeSlider so they can adjust the period they are viewing, making it easier to spot periods of interest.
A figure has been created, with line glyphs added. Additionally, earliest_date and lowest_date have been preloaded as the oldest and newest dates in the stocks["date"] column.
Este exercício faz parte do curso
Interactive Data Visualization with Bokeh
Instruções do exercício
- Import
DateRangeSlider. - Call
DateRangeSlider(), assigning"Date"to thetitle,earliest_dateandlatest_datetostartandend, settingvalueequal to"2014, 6, 2", "2018, 2, 7", and including an increment of1day per interaction with the widget. - Call
.js_link()twice, linking the widget's"value"to the"Start"and"End"offig'sx_rangeand setting the attribute selector to0and1in each call respectively. - Call
layout()to display thesliderabove thefig.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Import widget
____
earliest_date = stocks["date"].min()
latest_date = stocks["date"].max()
fig.line(apple["date"], apple["close"], color="green", legend_label="Apple")
fig.line(netflix["date"], netflix["close"], color="red", legend_label="Netflix")
fig.line(ibm["date"], ibm["close"], color="purple", legend_label="IBM")
fig.legend.location = "top_left"
# Create DateRangeSlider
slider = DateRangeSlider(title="____", start=____, end=____,
value=("____", "____"), step=____)
# Link DateRangeSlider values to figure
slider.____("____", ____.____, "____", attr_selector=____)
slider.____("____", ____.____, "____", attr_selector=____)
# Create layout and display plot
output_file(filename="stock_price_over_time.html")
show(____(____, ____))