Plot with filled area
-
I was trying to create filled area plot for the broker
value
observer. I've sub-classed existingvalue
observer, addzero
line, and filled area betweenvalue
andzero
lines, same approach as you used for ichimoku indicator. Finally ended with the following code:class ValueFilled(bt.Observer): lines = ('pnl', 'zero',) params = (('initial_cash', None),) plotinfo = dict(plot=True, subplot=True, plotname='Cumulative P/L') plotlines = dict(pnl=dict(ls='-', linewidth=1.0, color='black', _fill_gt=('zero', 'green'), _fill_lt=('zero', 'red'),), zero=dict(_plotskip=True,), ) def next(self): self.lines.pnl[0] = self._owner.broker.getvalue() - self.p.initial_cash self.lines.zero[0] = 0.0
Is there any easier way to draw filled area under/below the line? In the
plot.py
I've fond onlyax.fill_between
method, so created second line above to use it.Here is the link to the picture picture
Somehow pictures inserted into the post usually don't show up. -
Not now. But it would seem sensible to support not only a line name as the reference to fill (above/below) but also a numeric value.
-
You may try this commit: https://github.com/mementum/backtrader/commit/8ef8555d4fd5685b4811c848009bcd19e553e4a4
-
Thank you!
Since this is re-written, could you please get hard-coded
alpha
(line 471 of theplot.py
) for the fill to 'plotlines' parameter level? -
The latest commit to
development
allows thatThe Docs - Plotting has been updated to reflect the possibilities (you may need to use
Shift + F5
to bypass the browser cache) -
@backtrader Thank you!
It seems that you have a typo in the docs:
_fill_gt
/_less_gt
should be_fill_gt
/_fill_lt
.
At least latter works. -
Better in the docs as in the code. Updated