Skip to content

Commit 0210cf0

Browse files
committed
axes with twin plots added
1 parent 2220b1b commit 0210cf0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

oi_graph/futures_oi.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ def get_price_oi(data, symbol):
5151
agg['index'] = range(len(agg))
5252
return agg
5353

54+
def twin_plot(data, y_axis, x_axis='timestamp'):
55+
"""
56+
Create a bokeh plot with twin axes
57+
"""
58+
from bokeh.plotting import figure
59+
from bokeh.models import LinearAxis, Range1d
60+
61+
TOOLTIPS = [
62+
('datetime', '@x{%F %H:%M}'),
63+
('value', '$y{0.00}')
64+
]
65+
66+
y1,y2 = y_axis[0], y_axis[1]
67+
h0 = data[y1].max()
68+
l0 = data[y1].min()
69+
h1 = data[y2].max()
70+
l1 = data[y2].min()
71+
p = figure(x_axis_type='datetime', y_range=(l0, h0),
72+
tooltips=TOOLTIPS, height=240, width=600)
73+
p.line(data[x_axis].values, data[y1].values,
74+
color="red", legend=y1)
75+
p.extra_y_ranges = {"foo": Range1d(l1,h1)}
76+
p.line(data[x_axis], data[y2].values, color="blue",
77+
y_range_name="foo", legend=y2)
78+
p.add_layout(LinearAxis(y_range_name="foo", axis_label=y2), 'left')
79+
p.hover.formatters= {'x': 'datetime'}
80+
p.legend.location = 'top_center'
81+
p.legend.click_policy = 'hide'
82+
return p
5483

5584
output_file('futures_oi.html')
5685
df = load_data()

0 commit comments

Comments
 (0)