Animations of marks and axes can be enabled by setting 'animation_duration' property of the figure

Line Animations


In [ ]:
import numpy as np
from bqplot import *

In [ ]:
xs = LinearScale()
ys = LinearScale()
x = np.arange(100)
y = np.cumsum(np.random.randn(2, 100), axis=1) #two random walks

line = Lines(x=x, y=y, scales={'x': xs, 'y': ys}, colors=['red', 'green'])
xax = Axis(scale=xs, label='x', grid_lines='solid')
yax = Axis(scale=ys, orientation='vertical', tick_format='0.2f', label='y', grid_lines='solid')

Figure(marks=[line], axes=[xax, yax], animation_duration=1000)

In [ ]:
# update data of the line mark
line.y = np.cumsum(np.random.randn(2, 100), axis=1)

Scatter Animations


In [ ]:
xs = LinearScale()
ys = LinearScale()
x, y = np.random.rand(2, 20)
scatt = Scatter(x=x, y=y, scales={'x': xs, 'y': ys}, colors=['blue'])
xax = Axis(scale=xs, label='x', grid_lines='solid')
yax = Axis(scale=ys, orientation='vertical', tick_format='0.2f', label='y', grid_lines='solid')

Figure(marks=[scatt], axes=[xax, yax], animation_duration=1000)

In [ ]:
#data updates
scatt.x = np.random.rand(20) * 10
scatt.y = np.random.rand(20)

Pie Animations


In [ ]:
data = np.random.rand(6)
pie = Pie(sizes=data, radius=180, sort=False, 
          display_labels='outside', display_values=True,
          values_format='.0%', labels=list('ABCDEFGHIJ'))
Figure(marks=[pie], animation_duration=1000)

In [ ]:
pie.sizes = np.random.rand(8)

In [ ]:
pie.sort = True

In [ ]:
#make pie a donut
with pie.hold_sync():
    pie.radius = 180
    pie.inner_radius = 120

Bar animations


In [ ]:
n = 10
x = list('ABCDEFGHIJ')
y1, y2 = np.random.rand(2, n)

In [ ]:
xs = OrdinalScale()
ys = LinearScale()

bar = Bars(x=x, y=[y1, y2], scales={'x': xs, 'y': ys}, padding=0.2, type='grouped')
xax = Axis(scale=xs)
yax = Axis(scale=ys, orientation='vertical', tick_format='0.0%', grid_lines='solid')

Figure(marks=[bar], axes=[xax, yax], animation_duration=1000)

In [ ]:
y1, y2 = np.random.rand(2, n)
bar.y = [y1, y2]

Multiple Mark Animations


In [ ]:
xs = LinearScale()
ys1 = LinearScale()
ys2 = LinearScale()

x = np.arange(20)
y = np.cumsum(np.random.randn(20))
y1 = np.random.rand(20)

line = Lines(x=x, y=y, scales={'x': xs, 'y': ys1}, colors=['magenta'], marker='square')
bar = Bars(x=x, y=y1, scales={'x': xs, 'y': ys2}, colorpadding=0.2, colors=['steelblue'])

xax = Axis(scale=xs, label='x', grid_lines='solid')
yax1 = Axis(scale=ys1, orientation='vertical', tick_format='0.1f', label='y', grid_lines='solid')
yax2 = Axis(scale=ys2, orientation='vertical', side='right', tick_format='0.0%', label='y1', grid_lines='none')

Figure(marks=[bar, line], axes=[xax, yax1, yax2], animation_duration=1000)

In [ ]:
# update mark data
line.y = np.cumsum(np.random.randn(20))
bar.y = np.random.rand(20)