JSBGym调用render()时出现ArtistList无pop()方法的属性错误
解决JSBGym中env.render()触发的AttributeError问题
问题根源
matplotlib版本更新后,subplot.lines返回的对象从普通列表变为ArtistList,而ArtistList不支持pop()方法,导致原代码的subplot.lines.pop()触发报错。
修复步骤
- 打开项目内的
jsbgym/visualiser.py文件,定位到第64行的subplot.lines.pop()代码。 - 将这行代码替换为以下任意一种写法:
- 写法一(推荐):用
del语句按索引删除最后一个元素del subplot.lines[-1] - 写法二:先转为普通列表再执行pop操作
lines_list = list(subplot.lines) lines_list.pop()
- 写法一(推荐):用
- 保存文件后重新运行代码,
env.render()即可正常工作。
内容的提问来源于stack exchange,提问作者sryu1
相关产品推荐
相关产品推荐

