Plot doesn't show up when running the code
-
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
-
@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 createdmatplotlib
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 toautomatic
, change it toinline
and viceversa.
It's the problem with this Python kernel hijacking shells: they think they know better.
-
-
@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!
-
@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.Unless you are comfortable with
vim
oremacs
and don't mind using a standard shell (which for all intent and purposes happens to bebash
these days) -
I use Spyder and here is my solution (Some hack).
- Change the spyder setting : "Preferences" -> "IPython console" -> "Graphics" tab -> "Graphics backend" -> "Backend" -> "Automatic"
- Restart the current Console (The one inside spyder)
- 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')
- Plot with iplot = false
cerebro.plot(height= 30, iplot= False)
- Run your code and you should see a separate windows pop up
-
@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.
-
Try to run:
a = cerebro.plot() a[0][0]