@@ -190,7 +190,7 @@ def f(s, new_index=pd.Index(df.index.astype(np.int64)), bars=trades[column]):
190
190
def plot (* , results : pd .Series ,
191
191
df : pd .DataFrame ,
192
192
indicators : List [_Indicator ],
193
- filename = '' , plot_width = None ,
193
+ filename = '' , plot_width = None , plot_height = 400 ,
194
194
plot_equity = True , plot_return = False , plot_pl = True ,
195
195
plot_volume = True , plot_drawdown = False , plot_trades = True ,
196
196
smooth_equity = False , relative_equity = True ,
@@ -199,6 +199,15 @@ def plot(*, results: pd.Series,
199
199
show_legend = True , open_browser = True ):
200
200
"""
201
201
Like much of GUI code everywhere, this is a mess.
202
+
203
+ Parameters:
204
+ -----------
205
+ plot_width : int, optional
206
+ Width of the plot in pixels. If None (default), the plot is made
207
+ to span 100% of browser width.
208
+ plot_height : int, optional
209
+ Height of the main OHLC chart in pixels. Other sections are sized
210
+ proportionally. Default is 400.
202
211
"""
203
212
# We need to reset global Bokeh state, otherwise subsequent runs of
204
213
# plot() contain some previous run's cruft data (was noticed when
@@ -207,6 +216,16 @@ def plot(*, results: pd.Series,
207
216
filename = _windos_safe_filename (str (results ._strategy ))
208
217
_bokeh_reset (filename )
209
218
219
+ # Calculate proportional heights based on original ratios
220
+ # Original OHLC height was 400px, use that as base ratio
221
+ base_height = plot_height
222
+ equity_height = int (base_height * 0.25 ) # was 100px
223
+ equity_height_with_dd = int (base_height * 0.2 ) # was 80px
224
+ drawdown_height = int (base_height * 0.2 ) # was 80px
225
+ pl_height = int (base_height * 0.2 ) # was 80px
226
+ volume_height = int (base_height * 0.175 ) # was 70px
227
+ indicator_height = int (base_height * 0.125 ) # was 50px
228
+
210
229
COLORS = [BEAR_COLOR , BULL_COLOR ]
211
230
BAR_WIDTH = .8
212
231
@@ -240,7 +259,7 @@ def plot(*, results: pd.Series,
240
259
_figure ,
241
260
x_axis_type = 'linear' ,
242
261
width = plot_width ,
243
- height = 400 ,
262
+ height = base_height ,
244
263
# TODO: xwheel_pan on horizontal after https://github.com/bokeh/bokeh/issues/14363
245
264
tools = "xpan,xwheel_zoom,xwheel_pan,box_zoom,undo,redo,reset,save" ,
246
265
active_drag = 'xpan' ,
@@ -296,7 +315,7 @@ def plot(*, results: pd.Series,
296
315
('Volume' , '@Volume{0,0}' )]
297
316
298
317
def new_indicator_figure (** kwargs ):
299
- kwargs .setdefault ('height' , _INDICATOR_HEIGHT )
318
+ kwargs .setdefault ('height' , indicator_height )
300
319
fig = new_bokeh_figure (x_range = fig_ohlc .x_range ,
301
320
active_scroll = 'xwheel_zoom' ,
302
321
active_drag = 'xpan' ,
@@ -362,7 +381,7 @@ def _plot_equity_section(is_return=False):
362
381
source .add (equity , source_key )
363
382
fig = new_indicator_figure (
364
383
y_axis_label = yaxis_label ,
365
- ** (dict (height = 80 ) if plot_drawdown else dict (height = 100 )))
384
+ ** (dict (height = equity_height_with_dd ) if plot_drawdown else dict (height = equity_height )))
366
385
367
386
# High-watermark drawdown dents
368
387
fig .patch ('index' , 'equity_dd' ,
@@ -413,7 +432,7 @@ def _plot_equity_section(is_return=False):
413
432
414
433
def _plot_drawdown_section ():
415
434
"""Drawdown section"""
416
- fig = new_indicator_figure (y_axis_label = "Drawdown" , height = 80 )
435
+ fig = new_indicator_figure (y_axis_label = "Drawdown" , height = drawdown_height )
417
436
drawdown = equity_data ['DrawdownPct' ]
418
437
argmax = drawdown .idxmax ()
419
438
source .add (drawdown , 'drawdown' )
@@ -427,7 +446,7 @@ def _plot_drawdown_section():
427
446
428
447
def _plot_pl_section ():
429
448
"""Profit/Loss markers section"""
430
- fig = new_indicator_figure (y_axis_label = "Profit / Loss" , height = 80 )
449
+ fig = new_indicator_figure (y_axis_label = "Profit / Loss" , height = pl_height )
431
450
fig .add_layout (Span (location = 0 , dimension = 'width' , line_color = '#666666' ,
432
451
line_dash = 'dashed' , level = 'underlay' , line_width = 1 ))
433
452
trade_source .add (trades ['ReturnPct' ], 'returns' )
@@ -454,7 +473,7 @@ def _plot_pl_section():
454
473
455
474
def _plot_volume_section ():
456
475
"""Volume section"""
457
- fig = new_indicator_figure (height = 70 , y_axis_label = "Volume" )
476
+ fig = new_indicator_figure (height = volume_height , y_axis_label = "Volume" )
458
477
fig .yaxis .ticker .desired_num_ticks = 3
459
478
fig .xaxis .formatter = fig_ohlc .xaxis [0 ].formatter
460
479
fig .xaxis .visible = True
0 commit comments