Plotting error: Axis limits cannot be NaN or Inf
-
Hello there!
The simple code get an error, could you please give an advise what's may be wrong.from __future__ import (absolute_import, division, print_function, unicode_literals) import backtrader as bt from backtrader.feeds import GenericCSVData feed = 'XAU=.csv' data = GenericCSVData(dataname='.\\data\\' + feed, name=feed, dtformat='%d.%m.%Y', separator=';', datetime=0, time=-1, open=1, high=2, low=3, close=4, volume=-1, openinterest=-1) cerebro = bt.Cerebro() cerebro.adddata(data) cerebro.run() cerebro.plot()
Data in csv:
Date;Open;High;Low;Close
01.01.2010;1096.25;1096.9;1096.05;1096.35
04.01.2010;1095.85;1123.4;1093.05;1120
05.01.2010;1120.9;1127.7;1114.85;1118.65
06.01.2010;1118;1140.2;1115.6;1138.5
07.01.2010;1137.8;1138.75;1128.2;1131.9
08.01.2010;1131.35;1139.3;1119.45;1136.1
11.01.2010;1136.8;1161.5;1136.8;1152.6
12.01.2010;1151.15;1158;1124.95;1127.3Getting error:
Traceback (most recent call last):
File "C:/Users/-/YandexDisk/Codes Python/Algo/Bob GS/ex2.py", line 45, in <module>
cerebro.plot()
File "C:\Users-\backtrader_env\lib\site-packages\backtrader\cerebro.py", line 991, in plot
start=start, end=end, use=use)
File "C:\Users-\backtrader_env\lib\site-packages\backtrader\plot\plot.py", line 220, in plot
self.plotdata(data, self.dplotsover[data])
File "C:\Users-\backtrader_env\lib\site-packages\backtrader\plot\plot.py", line 634, in plotdata
data, opens, highs, lows, closes, volumes, vollabel)
File "C:\Users-\backtrader_env\lib\site-packages\backtrader\plot\plot.py", line 580, in plotvolume
ax.set_ylim(0, volylim, auto=True)
File "C:\Users-\backtrader_env\lib\site-packages\matplotlib\axes_base.py", line 3226, in set_ylim
top = self._validate_converted_limits(top, self.convert_yunits)
File "C:\Users-\backtrader_env\lib\site-packages\matplotlib\axes_base.py", line 2836, in _validate_converted_limits
raise ValueError("Axis limits cannot be NaN or Inf")
ValueError: Axis limits cannot be NaN or InfThank you!
-
@oalexandere said in Plotting error: Axis limits cannot be NaN or Inf:
File "C:\Users\osipov\backtrader_env\lib\site-packages\backtrader\plot\plot.py", line 580, in plotvolume
That should be the key line since there seems to be no volume in your data. Try plotting disabling the volume.
-
Thanks! Works
cerebro.plot(volume=False)
But in page https://www.backtrader.com/docu/plotting/plotting.html
I found:# Wether to plot volume or not. Note: if the data in question has no # volume values, volume plotting will be skipped even if this is True self.volume = True
A little bit strange, thought changing to Flase will be automatically.
-
Which is probably
True
(written in the best Python tradition) if your volume is0
, but since you have no volume and reading the error message:ValueError: Axis limits cannot be NaN or Inf
it seems your volume is probably given a value of
Nan
. It might even be thatNaN
evaluates slightly different between Python 2.7 and 3.x.