Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Plotly & Backtrader?

    General Code/Help
    2
    3
    1073
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      titan last edited by

      Has anyone been able to get Plotly working with Backtrader? I thought that the plot_mpl or mpl_plotly methods would work but I keep running into the following error. Am I just calling something incorrectly?

      Traceback (most recent call last):
        File "C:/Users/sgh31/PycharmProjects/Algorithmic Trading/AlpacaTutorial.py", line 79, in <module>
          plotly.offline.plot_mpl(result[0], filename='simple_candlestick.html')
        File "C:\Users\sgh31\PycharmProjects\Algorithmic Trading\venv\lib\site-packages\plotly\offline\offline.py", line 833, in plot_mpl
          plotly_plot = tools.mpl_to_plotly(mpl_fig, resize, strip_style, verbose)
        File "C:\Users\sgh31\PycharmProjects\Algorithmic Trading\venv\lib\site-packages\plotly\tools.py", line 470, in mpl_to_plotly
          matplotlylib.Exporter(renderer).run(fig)
        File "C:\Users\sgh31\PycharmProjects\Algorithmic Trading\venv\lib\site-packages\plotly\matplotlylib\mplexporter\exporter.py", line 45, in run
          if fig.canvas is None:
      AttributeError: 'list' object has no attribute 'canvas'
      

      For reference, my code is below. I'm just using a simple strategy as a POC to see if Plotly can work with backtrader

      # Store the figures returned by cerebro.plot() and plot them w/plotly
      result = cerebro.plot()
      plotly.offline.plot_mpl(result[0], filename='simple_candlestick.html')
      
      1 Reply Last reply Reply Quote 0
      • T
        titan last edited by

        Update:

        Changing it to the following seemed to work but I'm confused as to why. It looks like it was a list within a list but I can't figure out why it was nested that way with Cerebro.plot()

        # Store the figures returned by cerebro.plot() and plot them w/plotly
        result = cerebro.plot()
        plotly.offline.plot_mpl(result[0][0], filename='simple_candlestick.html')
        
        1 Reply Last reply Reply Quote 0
        • eeilon79
          eeilon79 last edited by

          I have been having the same issue. I've tried the fixed code above and the conversion of matplotlib graph was only partially successful - the candle chart was eliminated and the plotly results seems distorted and unclear. Is there any other alternative for plotly support? I've seen OmegaUI, not sure I need something this sophisticated.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
          $(document).ready(function () { app.coldLoad(); }); }