A context manager that batches up trace and layout assignment operations into a singe plotly_update message that is executed when the context exits.


For example, suppose we have a figure widget, fig, with a single trace.

>>> import plotly.graph_objs as go
>>> fig = go.FigureWidget(data=[{'y': [3, 4, 2]}])

If we want to update the xaxis range, the yaxis range, and the marker color, we could do so using a series of three property assignments as follows:

>>> fig.layout.xaxis.range = [0, 5]
>>> fig.layout.yaxis.range = [0, 10]
>>>[0].marker.color = 'green'

This will work, however it will result in three messages being sent to the front end (two relayout messages for the axis range updates followed by one restyle message for the marker color update). This can cause the plot to appear to stutter as the three updates are applied incrementally.

We can avoid this problem by performing these three assignments in a batch_update context as follows:

>>> with fig.batch_update():
...     fig.layout.xaxis.range = [0, 5]
...     fig.layout.yaxis.range = [0, 10]
...[0].marker.color = 'green'

Now, these three property updates will be sent to the frontend in a single update message, and they will be applied by the front end simultaneously.