Updating Plots
In bqplot
almost all the attributes of plotting widgets (Figure, Mark, Scale, Axis) are implemented as traitlets, so the plots are responsive to data updates. All you need to do is update the attributes in place without having to recreate the figure
and mark
objects.
Updating the attributes of figure
and marks
automatically triggers a re-draw of the plots on the front-end.
Let's look at an example:
import numpy as np
import bqplot.pyplot as plt
x = np.linspace(-10, 10, 100)
y = np.sin(x)
fig = plt.figure()
curve = plt.plot(x, y)
fig
Updating Single Data Attribute
Let's look at the correct (and incorrect) way of updating the plots:
Correct
Only update the figure
and mark
attributes like so:
Incorrect
Do not create figure
and mark
objects again to update the plots!
Updating Multiple Data Attributes
We can update multiple attributes of the mark
object simultaneously by using the hold_sync
method like so. (This makes only one round trip from the python kernel to the front end)
Efficient
Only one network trip
Animations
We can enable animated data updates by passing in animation_duration
(in milliseconds) to the figure. Let's look at an example to update a scatter plot