Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plot method for inline rendering #482

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions backtrader/cerebro.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def getbroker(self):
broker = property(getbroker, setbroker)

def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
width=16, height=9, dpi=300, tight=True, use=None,
width=None, height=None, dpi=None, tight=True, use=None,
**kwargs):
'''
Plots the strategies inside cerebro
Expand All @@ -964,11 +964,11 @@ def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
``datetime.date``, ``datetime.datetime`` instance indicating the end
of the plot

``width``: in inches of the saved figure
``width``: in inches of the saved figure and inline display

``height``: in inches of the saved figure
``height``: in inches of the saved figure and inline display

``dpi``: quality in dots per inches of the saved figure
``dpi``: quality in dots per inches of the saved figure and inline display

``tight``: only save actual content and not the frame of the figure
'''
Expand All @@ -977,6 +977,14 @@ def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,

if not plotter:
from . import plot

if height is not None:
kwargs['height'] = height
if width is not None:
kwargs['width'] = width
if dpi is not None:
kwargs['dpi'] = dpi

if self.p.oldsync:
plotter = plot.Plot_OldSync(**kwargs)
else:
Expand All @@ -993,7 +1001,7 @@ def plot(self, plotter=None, numfigs=1, iplot=True, start=None, end=None,
for si, strat in enumerate(stratlist):
rfig = plotter.plot(strat, figid=si * 100,
numfigs=numfigs, iplot=iplot,
start=start, end=end, use=use)
start=start, end=end, use=use, **kwargs)
# pfillers=pfillers2)

figs.append(rfig)
Expand Down
11 changes: 7 additions & 4 deletions backtrader/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def __init__(self, sch):

self.prop = mfontmgr.FontProperties(size=self.sch.subtxtsize)

def newfig(self, figid, numfig, mpyplot):
fig = mpyplot.figure(figid + numfig)
def newfig(self, figid, numfig, mpyplot, height, width, dpi):
fig = mpyplot.figure(figid + numfig, figsize = (height, width), dpi = dpi)
self.figs.append(fig)
self.daxis = collections.OrderedDict()
self.vaxis = list()
Expand Down Expand Up @@ -133,6 +133,10 @@ def plot(self, strategy, figid=0, numfigs=1, iplot=True,
import matplotlib.pyplot as mpyplot
self.mpyplot = mpyplot

width = kwargs.get('width', mpyplot.rcParams["figure.figsize"][0])
height = kwargs.get('height', mpyplot.rcParams["figure.figsize"][1])
dpi = kwargs.get('dpi', mpyplot.rcParams["figure.dpi"])

self.pinf = PInfo(self.p.scheme)
self.sortdataindicators(strategy)
self.calcrows(strategy)
Expand Down Expand Up @@ -167,7 +171,7 @@ def plot(self, strategy, figid=0, numfigs=1, iplot=True,

for numfig in range(numfigs):
# prepare a figure
fig = self.pinf.newfig(figid, numfig, self.mpyplot)
fig = self.pinf.newfig(figid, numfig, self.mpyplot, height, width, dpi)
figs.append(fig)

self.pinf.pstart, self.pinf.pend, self.pinf.psize = pranges[numfig]
Expand Down Expand Up @@ -252,7 +256,6 @@ def plot(self, strategy, figid=0, numfigs=1, iplot=True,
lastax = laxis[i]
if lastax not in self.pinf.vaxis:
break

i -= 1

self.setlocators(lastax) # place the locators/fmts
Expand Down