Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Plot - maximize windows

    General Code/Help
    4
    7
    8604
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Maxim Korobov
      Maxim Korobov last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        You can subclass Plot which is in backtrader.plot and then override the method show.

        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 of cerebro.plot:

        • https://www.backtrader.com/docu/cerebro.html#backtrader.Cerebro.plot

        Note: disregard the useplotly parameter (it was a failed experiment which should be removed)

        1 Reply Last reply Reply Quote 1
        • Maxim Korobov
          Maxim Korobov last edited by

          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)
          
          1 Reply Last reply Reply Quote 0
          • hans
            hans last edited by

            Just for people working on a mac: the solution described above does not seem to work on macOS (at least not in my environment).

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by backtrader

              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:

              • http://stackoverflow.com/questions/39312957/how-can-i-maximize-my-figure-on-matplotlib-python-using-macos

              And

              • http://stackoverflow.com/questions/12439588/how-to-maximize-a-plt-show-window-using-python/22418354#22418354

              There is no single solution.

              1 Reply Last reply Reply Quote 0
              • hans
                hans last edited by

                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.

                P 1 Reply Last reply Reply Quote 0
                • P
                  phat @hans last edited by

                  @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!

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors