✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Threshold sliders in plotly express

Hello there! I’ve been trying to figure out how to use plotly.express’s “animation_frame” argument to create a pie chart with a slider that changes the threshold for plotted values. Right now, the only solution I can come up with is to copy and append rows to the dataframe according to whether they’re above each threshold value…seems clunky.

The other method I found is using graphical objects in regular plotly: https://plotly.com/python/sliders/. But just wondering if I’m missing something in the plotly.express documentation that might make it more simple.


Hi @smadug2 welcome to the forum! I think you should use graph_objects here; plotly express animations multitply the number of traces by the number of animation frames; they work better if your trace has the same number of points for each frame (which is not the case here with the threshold), and in any case you need indeed to have one row per point to be plotted so you need to copy the rows above each threshold value. With a fully configurable slider you can change directly the x and y data using update as the method, using just one trace, or you can change the value to be zero if under the threshold. Note that you also need to copy some data with the graph_objects method, you just do it when defining the steps.

Hi Emmanuelle, thanks so much for the advice. The solution you suggested worked great!