In [ ]:
import numpy as np
import bqplot.pyplot as plt
In [ ]:
x = np.linspace(0, 10, 20)
y = x**3
fig = plt.figure(animation_duration=1000)
scatter = plt.scatter(x, y)
plt.show()
In [ ]:
scatter.y = np.cos(x)
In [ ]:
scatter.y = np.exp(x)
In [ ]:
from bqplot.interacts import (
FastIntervalSelector, IndexSelector, BrushIntervalSelector,
BrushSelector, MultiSelector, LassoSelector,
)
In [ ]:
scatter.selected_style = {'opacity': '1'}
scatter.unselected_style = {'opacity': '0.2'}
brushintsel = BrushIntervalSelector(scale=scatter.scales['x'], marks=[scatter])
fig.interaction = brushintsel
In [ ]:
brushintsel
In [ ]:
scatter.selected
In [ ]:
import numpy as np
from bqplot import Pie, Figure
In [ ]:
data = np.random.rand(3)
pie = Pie(sizes=data, display_labels='outside')
fig = Figure(marks=[pie], animation_duration=1000)
fig
In [ ]:
n = np.random.randint(1, 10)
pie.sizes = np.random.rand(n)
In [ ]:
import pandas as pd
from bqplot import *
In [ ]:
price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[1.0, -0.8], [-0.8, 1.0]]), axis=0) + 100,
columns=['Security 1', 'Security 2'], index=pd.date_range(start='01-01-2007', periods=150))
dates_all = price_data.index.values
symbols = ['Security 1', 'Security 2']
sec1_levels = np.array(price_data[symbols[0]].values.flatten())
log_sec1 = np.log(sec1_levels)
sec1_returns = log_sec1[1:] - log_sec1[:-1]
sec2_levels = np.array(price_data[symbols[1]].values.flatten())
sc_x = DateScale()
sc_y = LinearScale()
sc_c1 = ColorScale()
scatter = Scatter(x=dates_all, y=sec2_levels, color=sec1_returns,
scales={'x': sc_x, 'y': sc_y, 'color': sc_c1},
stroke='black')
ax_y = Axis(label='Security 2', scale=sc_y,
orientation='vertical', side='left')
ax_x = Axis(label='Date', scale=sc_x, num_ticks=10, label_location='end')
ax_c = ColorAxis(scale=sc_c1, tick_format='0.2%', label='Returns', orientation='vertical', side='right')
m_chart = dict(top=50, bottom=70, left=50, right=100)
Figure(axes=[ax_x, ax_c, ax_y], marks=[scatter], fig_margin=m_chart,
title='Scatter of Security 2 vs Dates')
In [ ]:
import numpy as np
import bqplot.pyplot as plt
from bqplot import *
from traitlets import observe
from ipywidgets import VBox, Button
In [ ]:
axes_options = {'x': {'label': 'x'}, 'y': {'label': 'y'}}
x = np.arange(100)
y = np.cumsum(np.random.randn(2, 100), axis=1)
fig = plt.figure(animation_duration=1000)
lines = plt.plot(x=x, y=y, colors=['red', 'green'], axes_options=axes_options)
def generate(_):
lines.y = np.cumsum(np.random.randn(2, 100), axis=1)
button = Button(description='Generate data', button_style='success')
button.on_click(generate)
VBox([fig, button])
In [ ]:
from ipywidgets import Widget
Widget.close_all()