In [ ]:
import numpy as np
import bqplot.pyplot as plt
In [ ]:
price_data1 = [['2015-01-02 00:00:00', [161.31, 163.31, 161.0, 162.06]],
['2015-01-05 00:00:00', [161.27, 161.27, 159.19, 159.51]],
['2015-01-06 00:00:00', [159.67, 159.96, 155.17, 156.07]],
['2015-01-07 00:00:00', [157.2, 157.2, 154.03, 155.05]],
['2015-01-08 00:00:00', [156.24, 159.044, 155.55, 158.42]],
['2015-01-09 00:00:00', [158.42, 160.34, 157.25, 159.11]],
['2015-01-12 00:00:00', [159.0, 159.25, 155.76, 156.44]],
['2015-01-13 00:00:00', [157.26, 159.97, 155.68, 156.81]],
['2015-01-14 00:00:00', [154.86, 156.49, 153.74, 155.8]],
['2015-01-15 00:00:00', [156.69, 156.97, 154.16, 154.57]]]
price_data2 = [['2015-01-02 00:00:00', [111.39, 111.44, 107.35, 109.33]],
['2015-01-05 00:00:00', [108.29, 108.65, 105.41, 106.25]],
['2015-01-06 00:00:00', [106.54, 107.43, 104.63, 106.26]],
['2015-01-07 00:00:00', [107.2, 108.2, 106.695, 107.75]],
['2015-01-08 00:00:00', [109.23, 112.15, 108.7, 111.89]],
['2015-01-09 00:00:00', [112.67, 113.25, 110.21, 112.01]],
['2015-01-12 00:00:00', [112.6, 112.63, 108.8, 109.25]],
['2015-01-13 00:00:00', [111.43, 112.8, 108.91, 110.22]],
['2015-01-14 00:00:00', [109.04, 110.49, 108.5, 109.8]],
['2015-01-15 00:00:00', [110.0, 110.06, 106.66, 106.82]]]
In [ ]:
# Split up the data into x and y points
from bqplot.traits import convert_to_date
dates1 = convert_to_date([d[0] for d in price_data1])
prices1 = [d[1] for d in price_data1]
dates2 = convert_to_date([d[0] for d in price_data2])
prices2 = [d[1] for d in price_data2]
In [ ]:
fig = plt.figure()
axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}
ohlc1 = plt.ohlc(dates1, prices1, marker='candle',
format='ohlc', stroke='blue',
display_legend=True, labels=['IBM US Equity'],
axes_options=axes_options)
ohlc2 = plt.ohlc(dates2, prices2, marker='bar',
colors=['dodgerblue', 'orange'], stroke='orange',
display_legend=True, labels=['AAPL US Equity'], format='ohlc',
axes_options=axes_options)
fig
In [ ]:
ohlc1.colors = [None, 'red']
In [ ]:
from bqplot import LogScale
fig = plt.figure()
# use log scale for x
plt.scales(scales={'x': LogScale()})
axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y', 'tick_format': '.2f'}}
ohlc3 = plt.ohlc(np.arange(len(dates2)) + 1, np.array(prices2) / 60,
marker='bar', colors=['dodgerblue','orange'])
fig
In [ ]:
ohlc3.marker = 'candle'
In [ ]:
from bqplot import OrdinalScale
fig = plt.figure()
plt.scales(scales={'x': OrdinalScale()})
axes_options = {'x': {'label': 'X', 'tick_format': '%d-%m-%Y'},
'y': {'label': 'Y', 'tick_format': '.2f'}}
ohlc3 = plt.ohlc(dates2, np.array(prices2) / 60, marker='candle',
colors=['dodgerblue','orange'],
axes_options=axes_options)
fig
In [ ]:
ohlc3.opacities = [0.1, 0.2]