For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

How to output plots in a dark theme?

  • 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.


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

    import matplotlib.pyplot as plt
    # run backtest...'dark_background') # call before plotting
        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:

    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.

Log in to reply