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/

    Plot doesn't show up when running the code

    General Code/Help
    plot figure noplot
    5
    7
    11077
    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.
    • K
      Knolch last edited by

      Hi all, I'm relatively new to Python. I'm doing my first steps with Backtrader and tried to run the sample code. I got a problem concerning the plot. The code runs fine but when it comes to the plot I only get the following output but not plot:

      [[<Figure size 640x480 with 5 Axes>]]

      I'm using the Anaconda-Distribution with Python 3.7 and Spyder on Win 10.
      Probably it's a noob question but I don't know how to solve this 'problem'.

      Thanks in advance

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @Knolch last edited by

        @knolch said in Plot doesn't show up when running the code:

        [[<Figure size 640x480 with 5 Axes>]]

        That's the result of this in the code

        cerebro.plot()
        

        Because plot does actually return the created matplotlib figure, should the user desire to do something with it. If you were assigning the return value to a variable, you wouldn't see that.

        The problem is Spyder. The configuration you have is preventing the chart from being displayed. Your options:

        • Try

          cerebro.plot(iplot=False)
          

          This disables automatic inline plotting detection in backtrader, but this is probably not going to help.

        • Have a look at the charting options in Spyder for plotting. If set to automatic, change it to inline and viceversa.

        It's the problem with this Python kernel hijacking shells: they think they know better.

        1 Reply Last reply Reply Quote 2
        • K
          Knolch last edited by Knolch

          @backtrader
          Thanks for your reply.
          I followed your steps but unfortunately it didn't work.
          I then switched to the standard Python IDLE as you mentioned it's a problem with Spyder and it worked out.

          I will not use Spyder now for developing and testing my trading strategies but do you have any recommendations what I could use instead?
          I mean IDLE works but it's very uncomfortable. Which Editor are you using for backtesting?

          Thanks for your help!

          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @Knolch last edited by

            @knolch said in Plot doesn't show up when running the code:

            I will not use Spyder now for developing and testing my trading strategies but do you have any recommendations what I could use instead?
            I mean IDLE works but it's very uncomfortable. Which Editor are you using for backtesting?

            Apparently people like PyCharm for which a Free Community edition is available.

            • https://www.jetbrains.com/pycharm/

            Unless you are comfortable with vim or emacs and don't mind using a standard shell (which for all intent and purposes happens to be bash these days)

            1 Reply Last reply Reply Quote 1
            • sobeasy
              sobeasy last edited by

              I use Spyder and here is my solution (Some hack).

              1. Change the spyder setting : "Preferences" -> "IPython console" -> "Graphics" tab -> "Graphics backend" -> "Backend" -> "Automatic"
              2. Restart the current Console (The one inside spyder)
              3. Import below in sequence
              import matplotlib
              import matplotlib.pyplot as plt
              
              import backtrader as bt
              import backtrader.indicators as btind
              import backtrader.analyzers as btanalyzers
              import backtrader.feeds as btfeeds
              import backtrader.strategies as btstrats
              import backtrader.plot
              
              matplotlib.use('Qt5Agg')
              plt.switch_backend('Qt5Agg')
              
              1. Plot with iplot = false
              cerebro.plot(height= 30, iplot= False)
              
              1. Run your code and you should see a separate windows pop up
              A 1 Reply Last reply Reply Quote -1
              • A
                ajry @sobeasy last edited by

                @sobeasy It seems to me that your solution should work. But it blows up for me (Spyder 3.3.6, Anaconda3, Win10 64 bit). Somehow, it really wants tkinter!

                ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'qt5' is currently running
                

                Time to try VS Code; PyCharm's footprint is too heavy.

                1 Reply Last reply Reply Quote 0
                • Jacky-Chang1024
                  Jacky-Chang1024 last edited by

                  Try to run:

                  a = cerebro.plot()
                  a[0][0]
                  
                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    Last post
                  Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors