Automotive stocks analysis
The hedge fund has asked you to produce a scatter plot to help them understand the financial performance of two automotive companies: Ford and General Motors.
You will build a plot displaying the close price for each day against the market cap (price multiplied by volume) for the two companies. The fund would like to be able to customize the x-axis, giving you a great chance to implement RangeSlider.
Este exercício faz parte do curso
Interactive Data Visualization with Bokeh
Instruções do exercício
- Import
RangeSlider. - Create
sliderwith a title of"Stock Price", the start of 10, end of 47, value matching the start and end values inside parentheses, and astepof 1 for each interaction with the widget. - Link the
slider's"value"to the start of the figure'sx_rangeattribute, assigning zero to the attribute selector. - Repeat to link the
slider's"value"to the end of the figure'sx_rangeattribute, assigning one to the attribute selector.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Import RangeSlider
____
fig = figure(x_axis_label="Stock Price ($)", y_axis_label="Market Cap")
fig.circle(x=ford["close"], y=ford["market_cap"], legend_label="Ford", fill_color="red", fill_alpha=0.5)
fig.circle(x=gm["close"], y=gm["market_cap"], legend_label="GM", fill_color="green", fill_alpha=0.5)
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0a")
# Create slider
slider = ____(title="____", start=____, end=____, value=(____, ____), step=____)
# Link to start of x-axis
slider.____("____", fig.____, "____", attr_selector=____)
# Link to end of x-axis
slider.____("____", fig.____, "____", attr_selector=____)
output_file(filename="Slider.html")
show(layout([slider], [fig]))