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/

    How to output plots in a dark theme?

    General Discussion
    3
    3
    237
    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.
    • Arthur Pendragon
      Arthur Pendragon last edited by

      Hey guys, I'm new to backtrader, anyone knows how to plot output with a dark background? I need it because I'm building a Telegram Bot and I wish the output would be black on background.

      Thanks in advance.

      Arthur

      1 Reply Last reply Reply Quote 0
      • R
        rho33 last edited by

        This gave me decent dark background plot without adding too much code.

        import matplotlib.pyplot as plt
        
        # run backtest...
        
        plt.style.use('dark_background') # call before plotting
        
        cerebro.plot(
            loc='grey', # changes color for 'line on close' plot otherwise it will plot black on black
            grid=False # the default gridlines didn't look good w/ dark background
        )
        
        fig = plt.gcf()
        # this will make the value tags at end of the lines readable. Otherwise it will plot white on white
        for ax in fig.axes:
            for text in ax.texts:
                text.set_color('black')
        
        plt.show()
        

        Backtrader plots using matplotlib so if you're familiar with it you can always plot with cerebro.plot(), get the current figure with fig = plt.gcf(), and alter the figure's elements from there.

        1 Reply Last reply Reply Quote 2
        • Mariano Volpedo
          Mariano Volpedo last edited by

          This is my whole dark theme, I´ve tried to emulate TradingView schema.

          plt.style.use('fivethirtyeight')
          
          plt.rcParams["figure.figsize"] = (10, 6)
          plt.rcParams['lines.linewidth'] = 1
          
          SIZE = 7
          plt.rcParams['axes.labelsize'] = SIZE
          plt.rcParams['ytick.labelsize'] = SIZE
          plt.rcParams['xtick.labelsize'] = SIZE
          plt.rcParams["font.size"] = SIZE
          
          COLOR = '1'
          plt.rcParams['text.color'] = COLOR
          plt.rcParams['axes.labelcolor'] = COLOR
          plt.rcParams['xtick.color'] = COLOR
          plt.rcParams['ytick.color'] = COLOR
          
          
          plt.rcParams['grid.linewidth']=0.1
          plt.rcParams['grid.color']="0.2"
          plt.rcParams['lines.color']="0.5"
          plt.rcParams['axes.edgecolor']="0.2"
          plt.rcParams['axes.linewidth']=0.5
          
          plt.rcParams['figure.facecolor']="#101622"
          plt.rcParams['axes.facecolor']="#101622"
          plt.rcParams["savefig.dpi"]=120
          dpi = plt.rcParams["savefig.dpi"]
          width = 700
          height = 1200
          plt.rcParams['figure.figsize'] = height/dpi, width/dpi
          plt.rcParams["savefig.facecolor"] ="#101622"
          plt.rcParams["savefig.edgecolor"]="#101622"
          
          plt.rcParams['legend.fontsize'] = SIZE
          plt.rcParams['legend.title_fontsize'] = SIZE + 1
          plt.rcParams['legend.labelspacing'] =0.25
          plt.rcParams['image.cmap']='tab10'
          1 Reply Last reply Reply Quote 2
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }