回溯交易者:属性错误:"RRuleLocator"对象没有属性"set_view_interval"



我是第一次运行Backtrader,在运行brain .plot()时遇到此问题:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 158
155 print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
157 # Plot the result
--> 158 cerebro.plot()
File /opt/homebrew/lib/python3.10/site-packages/backtrader-1.9.76.123-py3.10.egg/backtrader/cerebro.py:989, in Cerebro.plot(self, plotter, numfigs, iplot, start, end, width, height, dpi, tight, use, **kwargs)
987 for stratlist in self.runstrats:
988     for si, strat in enumerate(stratlist):
--> 989         rfig = plotter.plot(strat, figid=si * 100,
990                             numfigs=numfigs, iplot=iplot,
991                             start=start, end=end, use=use)
992         # pfillers=pfillers2)
994         figs.append(rfig)
File /opt/homebrew/lib/python3.10/site-packages/backtrader-1.9.76.123-py3.10.egg/backtrader/plot/plot.py:262, in Plot_OldSync.plot(self, strategy, figid, numfigs, iplot, start, end, **kwargs)
257 # Applying fig.autofmt_xdate if the data axis is the last one
258 # breaks the presentation of the date labels. why?
259 # Applying the manual rotation with setp cures the problem
260 # but the labels from all axis but the last have to be hidden
261 for ax in laxis:
--> 262     self.mpyplot.setp(ax.get_xticklabels(), visible=False)
264 self.mpyplot.setp(lastax.get_xticklabels(), visible=True,
265                   rotation=self.pinf.sch.tickrotation)
267 # Things must be tight along the x axis (to fill both ends)
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axes/_base.py:74, in _axis_method_wrapper.__set_name__.<locals>.wrapper(self, *args, **kwargs)
73 def wrapper(self, *args, **kwargs):
---> 74     return get_method(self)(*args, **kwargs)
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axis.py:1456, in Axis.get_ticklabels(self, minor, which)
1454 if minor:
1455     return self.get_minorticklabels()
-> 1456 return self.get_majorticklabels()
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axis.py:1413, in Axis.get_majorticklabels(self)
1411 def get_majorticklabels(self):
1412     """Return this Axis' major tick labels, as a list of `~.text.Text`."""
-> 1413     self._update_ticks()
1414     ticks = self.get_major_ticks()
1415     labels1 = [tick.label1 for tick in ticks if tick.label1.get_visible()]
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axis.py:1262, in Axis._update_ticks(self)
1257 def _update_ticks(self):
1258     """
1259     Update ticks (position and labels) using the current data interval of
1260     the axes.  Return the list of ticks that will be drawn.
1261     """
-> 1262     major_locs = self.get_majorticklocs()
1263     major_labels = self.major.formatter.format_ticks(major_locs)
1264     major_ticks = self.get_major_ticks(len(major_locs))
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/axis.py:1484, in Axis.get_majorticklocs(self)
1482 def get_majorticklocs(self):
1483     """Return this Axis' major tick locations in data coordinates."""
-> 1484     return self.major.locator()
File /opt/homebrew/lib/python3.10/site-packages/matplotlib/dates.py:1378, in AutoDateLocator.__call__(self)
1375 def __call__(self):
1376     # docstring inherited
1377     dmin, dmax = self.viewlim_to_dt()
-> 1378     locator = self.get_locator(dmin, dmax)
1379     return locator()
File /opt/homebrew/lib/python3.10/site-packages/backtrader-1.9.76.123-py3.10.egg/backtrader/plot/locator.py:226, in AutoDateLocator.get_locator(self, dmin, dmax)
222     locator = MicrosecondLocator(interval, tz=self.tz)
224 locator.set_axis(self.axis)
--> 226 locator.set_view_interval(*self.axis.get_view_interval())
227 locator.set_data_interval(*self.axis.get_data_interval())
228 return locator
AttributeError: 'RRuleLocator' object has no attribute 'set_view_interval'

我试过查看RRuleLocator,但是网上关于这个的文档很少。之前,我遇到了这个问题importterror不能导入name 'warnings'从& # 39;matplotlib。日期和解决它的git克隆从这个回购https://github.com/mementum/backtrader。任何想法吗?

我试图摆脱这些行,然后安装backtrader,但结果是这样的情节(所有混乱):在这里输入图像描述

我遇到了完全相同的问题,我的解决方案是直接在与RRuleLocator相关的轴对象上调用set_view_interval()方法。

打开locator.py文件。然后删除这两行:

locator.set_view_interval(*self.axis.get_view_interval())
locator.set_data_interval(*self.axis.get_data_interval())

并替换为:

self.axis.set_view_interval(*self.axis.get_view_interval())

最新更新