@@ -51,6 +51,35 @@ def get_price_oi(data, symbol):
51
51
agg ['index' ] = range (len (agg ))
52
52
return agg
53
53
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
54
83
55
84
output_file ('futures_oi.html' )
56
85
df = load_data ()
0 commit comments