import numpy as np
import bqplot.pyplot as plt

x = np.linspace(-10, 10, 100)
y = np.sin(x)

fig = plt.figure()
line = plt.plot(x=x, y=y)
fig

"""
Explanation: Updating Plots
bqplot is an interactive plotting library. Attributes of plots can be updated in place without recreating the whole figure and marks. Let's look at idiomatic ways of updating plots in bqplot
End of explanation
"""


# update y attribute of the line object
line.y = np.tan(x)

"""
Explanation: To update the attributes of the plot(x, y, color etc.) the correct way to do it is to update the attributes of the mark objects in place. Recreating figure or mark objects is not recommended
End of explanation
"""


# update both x and y together
with line.hold_sync():
    line.x = np.arange(100)
    line.y = x ** 3 - x

"""
Explanation: 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 front end)
End of explanation
"""


fig.animation_duration = 1000
line.y = np.cos(x)

"""
Explanation: We can also animate the changes to the x, y and other data attributes by setting the animation_duration property on the figure object. More examples of animations can found in the Animations notebook
End of explanation
"""


x, y = np.random.rand(2, 10)

fig = plt.figure(animation_duration=1000)
scat = plt.scatter(x=x, y=y)
fig

# update the x and y attreibutes in place using hold_sync
with scat.hold_sync():
    scat.x, scat.y = np.random.rand(2, 10)

"""
Explanation: Let's look at an example to update a scatter plot
End of explanation
"""


