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 ?



  • 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



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



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



  • @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?



  • 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
    


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

    It works perfectly :)


Log in to reply
 

});