In [1]:
import numpy as np
import pandas as pd
import bqplot.pyplot as plt
In [2]:
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 [3]:
fig = plt.figure(title='Basic Label Example')
test_line = plt.plot(np.arange(10), y_data[:10])
test_label = plt.label(['Test', 'Label', 'for', 'the', 'Data'],
x=np.arange(5), y=y_data[:5],
default_size=26, font_weight='bolder',
colors=['orange', 'red'], update_on_move=True)
fig
Setting the label attribute enable_move to True makes the label draggable
In [4]:
# now the labels can be moved by dragging them!
test_label.enable_move = True
In [5]:
fig = plt.figure()
test_line = plt.plot(np.arange(10), y_data)
test_label = plt.label(['Test Label'], default_size=26, font_weight='bolder', colors=['orange'])
test_label.x = [0.5]
test_label.y = [0.2]
fig
In [6]:
# Rotating the label
test_label.rotate_angle = 30
In [7]:
fig = plt.figure()
lines = plt.plot(price_data.index, price_data['Security 1'])
label = plt.label(['Pi-Day'], x=[np.datetime64('2007-03-14')], colors=['orange'])
label.y = [.5]
fig
In [8]:
# Setting an offset in pixels
label.x_offset = 100