Adding Customised Sliders
Learn what sliders are and how to use them in Plotly to subset data and add interactivity.
Our data
Here we explore the baseball dataset that contain important statistics in the columns seen below:
Custom sliders in Plotly Express
When creating a custom slider in Plotly Express, we can use the animation_frame argument, which sets the slider values to the corresponding pandas series.
In this example, we plot a baseball player’s Batting Average against their On Base Percentage. We then set the animation_frame to "Year" to accentuate that we wish to have slider values for each year so that we can observe how the dispersion of the data in a bivariate sense changes over time.
We have also allowed some extra hover information to be shown and have set the range_x and range_y as a list with the minimum and maximum x and y bounds, respectively.
Removing animation functionality
By running the following code, we notice that the type of our Plotly Express figure is that of plotly.graph_objs._figure.Figure.
type(fig)
We get the following:
plotly.graph_objs._figure.Figure
With these figure objects, we can then observe certain aspects of our graph, one being the complete "layout" of our figure, which we can then observe with dictionary-like syntax.
The output for this is quite large, but the key is noted below:
'updatemenus': [{'buttons': [{'args': ...