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/

    I save in file it's ok, but I want disable the on-screen display ?

    General Code/Help
    3
    7
    1524
    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.
    • mamos
      mamos last edited by

      Hello everyone, dear @backtrader.
      I solicit your help because I want to disable the display of the method cerebro.plot (), I wish only saved the image (which I managed) in a file. but now I want to disable the on-screen display.
      Thank you

      1 Reply Last reply Reply Quote 0
      • Robin Dhillon
        Robin Dhillon last edited by

        Just dont plot. Write up the savefig method and not the cerebro.plot. Try to read into the docs to see the plotting features.

        mamos 1 Reply Last reply Reply Quote 0
        • mamos
          mamos @Robin Dhillon last edited by

          @robin-dhillon Thank you for your quick response. Your message will help me.

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

            @Robin-Dhillon
            I can not understand the operation of savefig (), it seems to me that nothing is indicated about it in the doc?
            here is the code I used to save to a file:
            figure = cerebro.plot (style = 'candlebars') [0] [0]
            figure.savefig('example.png')

            @robin-dhillon with your advice i try this: Plot_OldSync.savefig ()
            I have as error savefig () missing 3 required positional arguments: 'self', 'fig', and 'filename'. I do not understand what coresspond the 'fig' ??
            Can someone please enlighten me?

            1 Reply Last reply Reply Quote 0
            • Robin Dhillon
              Robin Dhillon last edited by

              Hello @mamos so there is a workaround this. You would need to make some changes to the original plot functions. I have this code written up for you. put this function at the end of your cerebro initialization and you should be good.

              def saveplots(cerebro, numfigs=1, iplot=True, start=None, end=None,
                           width=16, height=9, dpi=300, tight=True, use=None, file_path = '', **kwargs):
              
                      from backtrader import plot
                      if cerebro.p.oldsync:
                          plotter = plot.Plot_OldSync(**kwargs)
                      else:
                          plotter = plot.Plot(**kwargs)
              
                      figs = []
                      for stratlist in cerebro.runstrats:
                          for si, strat in enumerate(stratlist):
                              rfig = plotter.plot(strat, figid=si * 100,
                                                  numfigs=numfigs, iplot=iplot,
                                                  start=start, end=end, use=use)
                              figs.append(rfig)
              
                      for fig in figs:
                          for f in fig:
                              f.savefig(file_path, bbox_inches='tight')
                      return figs
              
              saveplots(cerebro, file_path = 'savefig.png') #run it
              
              G 1 Reply Last reply Reply Quote 2
              • mamos
                mamos last edited by mamos

                @Robin-Dhillon Thank you so much for your help!

                It works perfectly :)

                1 Reply Last reply Reply Quote 0
                • G
                  giovangonzalez @Robin Dhillon last edited by

                  @robin-dhillon this is awesome!!! works like a charm!! Thanks for this.

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