Skip to content

Commit b467600

Browse files
committed
Add plotylimited option to control vertical scaling locking on data plots
1 parent f097b7b commit b467600

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

backtrader/dataseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def TName(cls, tframe):
5858

5959

6060
class DataSeries(LineSeries):
61-
plotinfo = dict(plot=True, plotind=True)
61+
plotinfo = dict(plot=True, plotind=True, plotylimited=True)
6262

6363
_name = ''
6464
_compression = 1

backtrader/plot/plot.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ def plotdata(self, data, indicators):
684684

685685
ax.yaxis.set_major_locator(mticker.MaxNLocator(prune='both'))
686686
# make sure "over" indicators do not change our scale
687-
ax.set_ylim(ax.get_ylim())
687+
if data.plotinfo._get('plotylimited', True):
688+
if axdatamaster is None:
689+
ax.set_ylim(ax.get_ylim())
688690

689691
if self.pinf.sch.volume:
690692
# if not self.pinf.sch.voloverlay:

docs2/plotting/plotting.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ These are controlled by this data set in *Indicators* and *Observers*::
109109
plotyticks=[],
110110
plothlines=[],
111111
plotforce=False,
112-
plotmaster=None,)
112+
plotmaster=None,
113+
plotylimited=True,
114+
)
113115

114116
Although ``plotinfo`` is shown as a ``dict`` during class definition, the
115117
metaclass machinery of *backtrader* turns that into an object which is
@@ -223,6 +225,17 @@ The meaning of the options
223225
**Monthly** data but is meant for **Daily** data. It only makes sense to
224226
plot it on the *daily* data which is where the indicator makes sense.
225227

228+
- ``plotylimited``: currently only applies to data feeds. If ``True``
229+
(default), other lines on the data plot don't change the scale. Example:
230+
Bollinger Bands (top and bottom) may be far away from the actual absolute
231+
minimum/maximum of the data feed. With ```plotlimited=True``, those bands
232+
remain out of the chart, because the data controls the scaling. If set to
233+
``False``, the bands affects the y-scale and become visible on the chart
234+
235+
A use case is the ``PivotPoint`` indicator which is calculated on
236+
**Monthly** data but is meant for **Daily** data. It only makes sense to
237+
plot it on the *daily* data which is where the indicator makes sense.
238+
226239

227240
Line specific plotting options
228241
==============================

0 commit comments

Comments
 (0)