Plotting: how to get lines to have specific colours and thickness?
I just want to customize the colours and thicknesses of the various lines in Ichimoku.
I had no idea it was going to be this hard:
- There is no way to customize colours using the plotinfo variable, so I have to do this via PlotScheme (which didn't work either)
- There also isn't a way to customize line thickness, only on horizontal lines. Why?
From the documentation on Plotting:
I can pass a custom list to cerebro.plot as lcolors:
lcolors=['blue', 'green', 'red', 'turquoise']
But since PlotScheme.color() uses tab10_index, I cannot change the order in which the colours are used!
tab10_index = [3, 0, 2, 1, 2, 4, 5, 6, 7, 8, 9]
So since 'turquoise' is index 3, it will be used first. Then blue, red, green. Why does there need to be an array that picks specific colours from the Tableau 10 palette in that specific order anyway?
OK, let's say the proper solution is to subclass PlotScheme. But I cannot import it either, even though I can import every other folder around it, and there is a init.py in backtrader/plot/:
In : import backtrader as bt In : bt.plot --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-4-f26508c6d1b4> in <module>() ----> 1 bt.plot AttributeError: module 'backtrader' has no attribute 'plot' In : bt.observers Out: <module 'backtrader.observers' from '/Users/shinichi/source/cryptocoins/backtrader/observers/__init__.py'> In : bt.signals Out: <module 'backtrader.signals' from '/Users/shinichi/source/cryptocoins/backtrader/signals/__init__.py'> In : bt.sizers Out: <module 'backtrader.sizers' from '/Users/shinichi/source/cryptocoins/backtrader/sizers/__init__.py'> In : bt.stores Out: <module 'backtrader.stores' from '/Users/shinichi/source/cryptocoins/backtrader/stores/__init__.py'> In :
I must be missing something here because backtrader looks pythonic, but is actually very confusing.
The documentation should make it more obvious that in order to customize plotting, the intended route is to subclass the Indicator and override its self.plotlines via self._plotinit(). Looking at plotlines=(dict()) doesn't help.
PeterCHK last edited by
I spent some time investigating this problem also.
For multiple lines plotting, I managed to change the colour inside ichimoku.py with plotlines.
Just paste the following inside the ichimoku.py and restart the iPython to make it work.
plotlines = dict( senkou_span_a=dict(_fill_gt=('senkou_span_b', 'cyan'), _fill_lt=('senkou_span_b', 'magenta'), color='blue'), senkou_span_b=dict(color='yellow'), tenkan_sen=dict(_name='TenK', color='red'), kijun_sen=dict(_name='KJ',color='green'), chikou_span=dict(_name='chi', color='black') )
What about simply subclassing
Ichimokuand having that
plotlinesdefinition?. As in
class MyIchimoku(bt.indicators.Ichimoku): plotlines = dict( senkou_span_a=dict(_fill_gt=('senkou_span_b', 'cyan'), _fill_lt=('senkou_span_b', 'magenta'), color='blue'), senkou_span_b=dict(color='yellow'), tenkan_sen=dict(_name='TenK', color='red'), kijun_sen=dict(_name='KJ',color='green'), chikou_span=dict(_name='chi', color='black') )
And then of course using your subclass instead of the internal indicator.
Another, maybe clearer, option is:
ichimoku = bt.indicators.Ichimoku() ichimoku.plotlines.senkou_span_b.color = "yellow" [...]