Skip to content

Commit 5bcaafd

Browse files
committed
ENH: Make plot span 100% of browser width by default
1 parent a43ced9 commit 5bcaafd

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

backtesting/_plotting.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def lightness(color, lightness=.94):
6969
return color.to_rgb()
7070

7171

72-
def plot(*, results, df, indicators, filename='', plot_width=1200,
72+
def plot(*, results, df, indicators, filename='', plot_width=None,
7373
plot_equity=True, plot_pl=True,
7474
plot_volume=True, plot_drawdown=False,
7575
smooth_equity=False, relative_equity=True, omit_missing=True,
@@ -550,13 +550,17 @@ def __eq__(self, other):
550550
wheelzoom_tool = next(wz for wz in f.tools if isinstance(wz, WheelZoomTool))
551551
wheelzoom_tool.maintain_focus = False
552552

553+
kwargs = {}
554+
if plot_width is None:
555+
kwargs['sizing_mode'] = 'stretch_width'
556+
553557
fig = gridplot(
554558
plots,
555559
ncols=1,
556560
toolbar_location='right',
557-
# sizing_mode='stretch_width',
558561
toolbar_options=dict(logo=None),
559562
merge_tools=True,
563+
**kwargs
560564
)
561565
show(fig, browser=None if open_browser else 'none')
562566
return fig

backtesting/backtesting.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ def _round_timedelta(value, _period=_data_period(df)):
934934
s._trade_data = df # Private API
935935
return s
936936

937-
def plot(self, *, results: pd.Series = None, filename=None, plot_width=1200,
937+
def plot(self, *, results: pd.Series = None, filename=None, plot_width=None,
938938
plot_equity=True, plot_pl=True,
939939
plot_volume=True, plot_drawdown=False,
940940
smooth_equity=False, relative_equity=True,
@@ -953,11 +953,10 @@ def plot(self, *, results: pd.Series = None, filename=None, plot_width=1200,
953953
By default, a strategy/parameter-dependent file is created in the
954954
current working directory.
955955
956-
`plot_width` is the width of the plot in pixels. The height is
956+
`plot_width` is the width of the plot in pixels. If None (default),
957+
the plot is made to span 100% of browser width. The height is
957958
currently non-adjustable.
958959
959-
.. TODO:: Make Bokeh plot span 100% browser width by default.
960-
961960
If `plot_equity` is `True`, the resulting plot will contain
962961
an equity (cash plus assets) graph section.
963962

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'typing ; python_version < "3.5"',
3434
'numpy',
3535
'pandas >= 0.21.0, != 0.25.0',
36-
'bokeh >= 0.12.15',
36+
'bokeh >= 1.1.0',
3737
],
3838
extras_require={
3939
'doc': [

0 commit comments

Comments
 (0)