Skip to content

Commit 0581c55

Browse files
authored
Auto-scale Y-axis for indicators when zooming kernc#356
1 parent 0a76e96 commit 0581c55

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

backtesting/_plotting.py

+12
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ def __eq__(self, other):
523523
colors = colors and cycle(_as_list(colors)) or (
524524
cycle([next(ohlc_colors)]) if is_overlay else colorgen())
525525
legend_label = LegendStr(value.name)
526+
527+
indicator_max=value.df.max(axis='columns')
528+
indicator_min=value.df.min(axis='columns')
529+
source.add(indicator_max, f'indicator_{j}_range_max')
530+
source.add(indicator_min,f'indicator_{j}_range_min')
531+
526532
for j, arr in enumerate(value, 1):
527533
color = next(colors)
528534
source_name = f'{legend_label}_{i}_{j}'
@@ -609,6 +615,12 @@ def __eq__(self, other):
609615
source=source)
610616
if plot_volume:
611617
custom_js_args.update(volume_range=fig_volume.y_range)
618+
619+
indicator_ranges = {}
620+
for idx,indicator in enumerate(indicator_figs):
621+
indicator_range_key = f'indicator_{idx}_range'
622+
indicator_ranges.update({indicator_range_key:indicator.y_range})
623+
custom_js_args.update({'indicator_ranges':indicator_ranges})
612624

613625
fig_ohlc.x_range.js_on_change('end', CustomJS(args=custom_js_args,
614626
code=_AUTOSCALE_JS_CALLBACK))

0 commit comments

Comments
 (0)