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:

    1. There is no way to customize colours using the plotinfo variable, so I have to do this via PlotScheme (which didn't work either)
    2. There also isn't a way to customize line thickness, only on horizontal lines. Why?

    From the documentation on Plotting:
    https://www.backtrader.com/docu/plotting/plotting.html

    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 [3]: import backtrader as bt
    
    In [4]: 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 [5]: bt.observers
    Out[5]: <module 'backtrader.observers' from '/Users/shinichi/source/cryptocoins/backtrader/observers/__init__.py'>
    
    In [6]: bt.signals
    Out[6]: <module 'backtrader.signals' from '/Users/shinichi/source/cryptocoins/backtrader/signals/__init__.py'>
    
    In [7]: bt.sizers
    Out[7]: <module 'backtrader.sizers' from '/Users/shinichi/source/cryptocoins/backtrader/sizers/__init__.py'>
    
    In [8]: bt.stores
    Out[8]: <module 'backtrader.stores' from '/Users/shinichi/source/cryptocoins/backtrader/stores/__init__.py'>
    
    In [9]: 
    

    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.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.