Plot - maximize windows
-
Inside Backtrader uses matplotlib. It's easy to make matplotlib show maximized windows (on Windows) when you can reach plotter. How one can do it when call plot() from Backtrader?
-
You can subclass
Plot
which is inbacktrader.plot
and then override the methodshow
.The default behavior is:
def show(self): self.mpyplot.show()
And you can call
cerebro.plot
with an instance of your subclass. See here for the signature ofcerebro.plot
:Note: disregard the
useplotly
parameter (it was a failed experiment which should be removed) -
Thank you!
It helps. Here is snippet, which maximized figure window under Windows:
import backtrader.plot as plt class Plotter(plt.Plot): def __init__(self): super().__init__(volup='#60cc73') # custom color for volume up bars def show(self): mng = self.mpyplot.get_current_fig_manager() mng.window.state('zoomed') self.mpyplot.show() ... plotter = Plotter() back_tester.plot(plotter=plotter)
-
Just for people working on a mac: the solution described above does not seem to work on macOS (at least not in my environment).
-
The solution plotted by Maxim is one of many (apparently for the
TkAGG
backend)There are several different backends and each has a different approach to the problem. For example:
And
There is no single solution.
-
An alternate, very simple, approach is to handle the window outside of backtrader. Personally I wrote a (tiny) script (in keyboard maestro, mac only) to just resize the window with a F2 keypress, exactly to the dimensions I prefer. This keeps your code clean and works simple and effective. Just run, and press a key if you want to see a bigger window with the graphical results.
-
@hans said in Plot - maximize windows:
roach is to handle the window outside of backtrader. Personally I wrote a (tiny) script (in keyboard maestro, mac only) to just resize the window with a F2 keypress, exactly to the dimensions I prefer. This keeps your code clean and works simple and effective. Just run, and press a key if you want to see a bigger window with the graphical results.
Hey, could you share the script you made for resizing the plot window, I am having the same issue. Thanks!