Get startedGet started for free

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.

This exercise is part of the course

Interactive Data Visualization with Bokeh

View Course

Exercise instructions

  • Import RangeSlider.
  • Create slider with a title of "Stock Price", the start of 10, end of 47, value matching the start and end values inside parentheses, and a step of 1 for each interaction with the widget.
  • Link the slider's "value" to the start of the figure's x_range attribute, assigning zero to the attribute selector.
  • Repeat to link the slider's "value" to the end of the figure's x_range attribute, assigning one to the attribute selector.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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]))
Edit and Run Code