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

Help with plotting



  • Hello folks at Backtrader :)
    First of all thanks for sharing such a beautiful software, as a fellow programmer I do appreciate all the passion you have poured into this project 👍👍👍

    Back to the issue, I found two difficulties while plotting:

    • in some corner cases there seem to be some issues with orders plotting, related to different data lengths, as you can see from this moving average crossover plot - here the full sample code.
      0_1551464484858_chart.png
    • in a Colab environment with Python 3.6.7 and Matplotlib 3.0.2, cerebro.plot throws the following: ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running. So far I only found this workaround to work consistently:
    try:
        %matplotlib
    except Exception:
        pass
    import matplotlib.pyplot as plt
    plt.rcParams['figure.figsize'] = [19, 10]
    cerebro.plot(iplot=False)
    

    Keep up the great work,
    Enrico Bonetti Vieno


  • administrators

    1. Plotting is only meant as a visual aid when possible. backtrader is not a charting platform.

    @ebonetti said in Help with plotting:

    in a Colab environment with Python 3.6.7 and Matplotlib 3.0.2, cerebro.plot throws the following: ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running.

    1. No idea what Colab environment is, but it seems to be another of those environments which hijack the Python kernel simply because they can ...


  • Actually a visual aid would be more than enough 😅 This is my actual use case ...
    0_1551547340305_download.png

    I checked out your code and I can't really see where the order scatter plot happens, can you point it out? At any rate would you be interested in a pull request?


Log in to reply
 

});