In [ ]:
from bqplot import *
import numpy as np
import pandas as pd
In [ ]:
np.random.seed(10)
price_data = pd.DataFrame(np.cumsum(np.random.randn(150, 2).dot([[0.5, 0.8], [0.8, 1.0]]), axis=0) + 100,
columns=['Security 1', 'Security 2'],
index=pd.date_range(start='01-01-2007', periods=150))
y_data = np.cumsum(np.random.randn(100))
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
test_line = Lines(x=np.arange(10), y=y_data[:10], scales={'x': x_sc, 'y': y_sc})
test_label = Label(x=np.arange(5), y=y_data[:5], scales={'x': x_sc, 'y': y_sc},
text=['Test', 'Label', 'for', 'the', 'Data'], default_size=26, font_weight='bolder',
colors=['orange', 'red'], update_on_move=True)
ax_x = Axis(scale=x_sc, label='X')
ax_y = Axis(scale=y_sc, orientation='vertical', tick_format='0.2f', label='Y')
Figure(marks=[test_label, test_line], axes=[ax_x, ax_y], title='Basic Label Example')
Setting the label attribute enable_move
to True
makes the label draggable
In [ ]:
test_label.enable_move = True
In [ ]:
x_sc = LinearScale()
y_sc = LinearScale()
test_line = Lines(x=np.arange(10), y=y_data, scales={'x': x_sc, 'y': y_sc})
test_label = Label(x=[0.5], y=[0.2], text=['Test Label'], default_size=26,
font_weight='bolder', colors=['orange'])
ax_x = Axis(scale=x_sc)
ax_y = Axis(scale=y_sc, orientation='vertical', tick_format='0.2f')
Figure(marks=[test_line, test_label], axes=[ax_x, ax_y])
In [ ]:
# Rotating the label
test_label.rotate_angle = 30
In [ ]:
dt_sc = DateScale()
y_sc = LinearScale()
lines = Lines(x=price_data.index.values, y=price_data['Security 1'].values, scales={'x': dt_sc, 'y': y_sc})
label = Label(x=[np.datetime64('2007-03-14')], y=[0.5], scales={'x': dt_sc}, text=['Pi-Day'], colors=['orange'])
ax_x = Axis(scale=dt_sc)
ax_y = Axis(scale=y_sc, orientation='vertical')
Figure(marks=[lines, label], axes=[ax_x, ax_y])
In [ ]:
# Setting an offset in pixel
label.x_offset = 100
In [ ]: