How to output plots in a dark theme?
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.
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.