Skip to content

Commit f3bba12

Browse files
committed
Partial plotting correction. May address #277
1 parent 517dd52 commit f3bba12

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

backtrader/cerebro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def getbroker(self):
613613

614614
broker = property(getbroker, setbroker)
615615

616-
def plot(self, plotter=None, numfigs=1, iplot=True, start=0, end=-1,
616+
def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
617617
**kwargs):
618618
'''
619619
Plots the strategies inside cerebro

backtrader/plot/plot.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def drawtag(self, ax, x, y, facecolor, edgecolor, alpha=0.9, **kwargs):
113113
**kwargs)
114114

115115
def plot(self, strategy, figid=0, numfigs=1, iplot=True,
116-
start=0, end=-1, **kwargs):
116+
start=None, end=None, **kwargs):
117117
# pfillers={}):
118118
if not strategy.datas:
119119
return
@@ -134,12 +134,20 @@ def plot(self, strategy, figid=0, numfigs=1, iplot=True,
134134
self.calcrows(strategy)
135135

136136
st_dtime = strategy.lines.datetime.plot()
137+
if start is None:
138+
start = 0
139+
if end is None:
140+
end = len(st_dtime)
141+
137142
if isinstance(start, datetime.date):
138143
start = bisect.bisect_left(st_dtime, date2num(start))
139144

140145
if isinstance(end, datetime.date):
141146
end = bisect.bisect_right(st_dtime, date2num(end))
142147

148+
if end < 0:
149+
end = len(st_dtime) + 1 + end # -1 = len() -2 = len() - 1
150+
143151
slen = len(st_dtime[start:end])
144152
d, m = divmod(slen, numfigs)
145153
pranges = list()
@@ -194,10 +202,11 @@ def plot(self, strategy, figid=0, numfigs=1, iplot=True,
194202
dtidx = bisect.bisect_left(xreal, dt)
195203
xdata.append(dtidx)
196204

197-
self.pinf.xstart = bisect.bisect_left(
198-
dts, xreal[xdata[0]])
199-
self.pinf.xend = bisect.bisect_right(
200-
dts, xreal[xdata[-1]])
205+
if False:
206+
self.pinf.xstart = bisect.bisect_left(
207+
dts, xreal[xdata[0]])
208+
self.pinf.xend = bisect.bisect_right(
209+
dts, xreal[xdata[-1]])
201210

202211
for ind in self.dplotsup[data]:
203212
self.plotind(

0 commit comments

Comments
 (0)