In [ ]:
import numpy as np
import bqplot.pyplot as plt
from bqplot import LinearScale, Axis, Lines, Bars, Figure
In [ ]:
axes_options = {'x': {'label': 'x'}, 'y': {'label': 'y'}}
In [ ]:
x = np.arange(100)
y = np.cumsum(np.random.randn(2, 100), axis=1) #two random walks
fig = plt.figure(animation_duration=1000)
lines = plt.plot(x=x, y=y, colors=['red', 'green'], axes_options=axes_options)
fig
In [ ]:
# update data of the line mark
lines.y = np.cumsum(np.random.randn(2, 100), axis=1)
In [ ]:
fig = plt.figure(animation_duration=1000)
x, y = np.random.rand(2, 20)
scatt = plt.scatter(x, y, colors=['blue'], axes_options=axes_options)
fig
In [ ]:
#data updates
scatt.x = np.random.rand(20) * 10
scatt.y = np.random.rand(20)
In [ ]:
data = np.random.rand(6)
fig = plt.figure(animation_duration=1000)
pie = plt.pie(data, radius=180, sort=False, display_labels='outside', display_values=True,
values_format='.0%', labels=list('ABCDEFGHIJ'))
fig
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
In [ ]:
n = 10
x = list('ABCDEFGHIJ')
y1, y2 = np.random.rand(2, n)
In [ ]:
fig = plt.figure(animation_duration=1000)
bar = plt.bar(x, [y1, y2], padding=0.2, type='grouped')
fig
In [ ]:
y1, y2 = np.random.rand(2, n)
bar.y = [y1, y2]
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)