Skip to content

Commit 12702e4

Browse files
committed
twin_plot added to grid
1 parent 9e8f63e commit 12702e4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

oi_graph/futures_oi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from bokeh.io import curdoc
55
from bokeh.layouts import row, column, gridplot, layout
66
from bokeh.palettes import Spectral6
7-
from bokeh.models import ColumnDataSource, Range1d
7+
from bokeh.models import ColumnDataSource, Range1d, LinearAxis
88
from bokeh.models.widgets import Select, Button
99
from bokeh.plotting import figure, output_file, show
1010

@@ -55,8 +55,6 @@ def twin_plot(data, y_axis, x_axis='timestamp'):
5555
"""
5656
Create a bokeh plot with twin axes
5757
"""
58-
from bokeh.plotting import figure
59-
from bokeh.models import LinearAxis, Range1d
6058

6159
TOOLTIPS = [
6260
('datetime', '@x{%F %H:%M}'),
@@ -96,13 +94,16 @@ def twin_plot(data, y_axis, x_axis='timestamp'):
9694
tooltips=[
9795
('date', '@date'),
9896
('value', '$y{0 a}')
99-
])
97+
],
98+
height=250)
10099
cols, data = get_open_interest(df, 'NIFTY')
101100
data['date'] = data.timestamp.dt.date.astype(str)
102101
colors = Spectral6[:len(cols)]
103102
source.data = source.from_df(data)
104103
print(cols, colors)
105104
p.vbar_stack(cols, width=0.6, x='index', color=colors, source=source)
105+
price_data = get_price_oi(df, 'NIFTY')
106+
price_chart = twin_plot(price_data, y_axis=['close', 'open_int'])
106107

107108
# setup callbacks
108109
def update():
@@ -114,6 +115,8 @@ def update():
114115
print(cols, symbol, max_val)
115116
p.y_range = Range1d(100, max_val)
116117
p.title.text = 'Open interest chart for {} futures'.format(symbol)
118+
pdata = get_price_data(df, symbol)
119+
price_chart = twin_plot(pdata, y_axis=['close', 'open_int'])
117120

118121

119122
# set up event triggers
@@ -124,6 +127,7 @@ def update():
124127
l = layout(
125128
column(
126129
row(select_symbol,button),
130+
price_chart,
127131
p)
128132
)
129133

0 commit comments

Comments
 (0)