Skip to content

Commit 0b8d6ae

Browse files
committed
Add _skipnan to plotlines to allow joining two points with a line
1 parent 2ea7aaa commit 0b8d6ae

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

backtrader/plot/plot.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,18 @@ def plotind(self, iref, ind,
438438
plotkwargs['zorder'] = self.pinf.zordernext(ax)
439439

440440
pltmethod = getattr(ax, lineplotinfo._get('_method', 'plot'))
441-
plottedline = pltmethod(self.pinf.xdata, lplot, **plotkwargs)
441+
442+
xdata, lplotarray = self.pinf.xdata, lplot
443+
if lineplotinfo._get('_skipnan', False):
444+
# Get the full array and a mask to skipnan
445+
lplotarray = np.array(lplot)
446+
lplotmask = np.isfinite(lplotarray)
447+
448+
# Get both the axis and the data masked
449+
lplotarray = lplotarray[lplotmask]
450+
xdata = np.array(xdata)[lplotmask]
451+
452+
plottedline = pltmethod(xdata, lplotarray, **plotkwargs)
442453
try:
443454
plottedline = plottedline[0]
444455
except:

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
1.9.61.122
2+
- Add `_skipnan` to plotlines to allow joining two points with a line
3+
14
1.9.60.122
25
- Remove unused files
36
- README update, Docstring corrections, documentation corrections

0 commit comments

Comments
 (0)