Skip to content

Commit d20ff2a

Browse files
beejayseamementum
authored andcommitted
If we want to save the plot, assume that it is being done headless. (mementum#315)
1 parent e90ad73 commit d20ff2a

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

backtrader/cerebro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
924924
for si, strat in enumerate(stratlist):
925925
rfig = plotter.plot(strat, figid=si * 100,
926926
numfigs=numfigs, iplot=iplot,
927-
start=start, end=end)
927+
start=start, end=end, savefig=savefig)
928928
# pfillers=pfillers2)
929929

930930
figs.append(rfig)

backtrader/plot/plot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,17 @@ def drawtag(self, ax, x, y, facecolor, edgecolor, alpha=0.9, **kwargs):
114114
**kwargs)
115115

116116
def plot(self, strategy, figid=0, numfigs=1, iplot=True,
117-
start=None, end=None, **kwargs):
117+
start=None, end=None, savefig=False, **kwargs):
118118
# pfillers={}):
119119
if not strategy.datas:
120120
return
121121

122122
if not len(strategy):
123123
return
124124

125+
if savefig:
126+
matplotlib.use('agg')
127+
125128
if iplot:
126129
if 'ipykernel' in sys.modules:
127130
matplotlib.use('nbagg')

0 commit comments

Comments
 (0)