Black Lives Matter. Please consider donating to Black Girls Code today.

Restyle vs NewPlot

According to the documentation, using Plotly.restyle is more efficient than Plotly.newplot.
For example, if my plot got three traces and I would like to update two of them (x and y data) using a for loop. Is it more efficient to do :

Plotly.restyle(myDiv, updateObj, 1); Plotly.restyle(myDiv, updateObj2, 2);

Or

Plotly.newPlot(myDiv, plotData);

I noticed that by using Plotly.restyle, the range selector won’t be updated. In the other hand, Plotly.newplot will update the range selector but will it decrease the performance even more ?

1 Like

Ploty.restyle only update traces objects.

To update layout objects, you’ll need to use Plotly.relayout.

I use Plotly.restyle to update my x and y data from the main plot.
I understand that range slider is part of the layout but it does not seem to include x and y data properties.
Even if I use Plotly.relayout, I do not know how to set my new layout using new values.

Can you share a reproducible snippet of what you tried so far?

I am sorry I was not really clear.
By pressing the “Restyle” button, my data will update (restyle) but the rangeslider won’t. How can I use relayout to update the rangeslider data ?

Here is a jsfiddle:

https://jsfiddle.net/oro77/8x0vg0rw/1/

Oh that’s a known bug - related to https://github.com/plotly/plotly.js/issues/686

We’re hoping to get it fixed in the 1.18.0 release.

Sorry for the inconvenience.

Ok thank you for the information !