【发布时间】:2020-09-21 04:21:24
【问题描述】:
我有以下代码:
sim = simulator()
fig, ax = plt.subplots()
scat = ax.scatter(sim.XY[:,0],sim.XY[:,1])
def animate(i):
sim.run()
scat.set_offsets(sim.XY) # update the data.
return scat
ani = FuncAnimation(fig, animate, interval=10, blit=True, save_count=50)
“sim”对象方法“sim.run()”更新 sim.XY,即 (100,2) 数组。
在我的第三行之后,我得到了预期的散点图。
但是当我尝试制作动画时(从第 5 行向下),我收到一条错误消息。有人可以帮忙吗:
Traceback (most recent call last):
File "C:\Users\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py", line 216, in process
func(*args, **kwargs)
File "C:\Users\anaconda3\lib\site-packages\matplotlib\animation.py", line 953, in _start
self._init_draw()
File "C:\Users\\anaconda3\lib\site-packages\matplotlib\animation.py", line 1732, in _init_draw
self._draw_frame(next(self.new_frame_seq()))
File "C:\Users\anaconda3\lib\site-packages\matplotlib\animation.py", line 1761, in _draw_frame
key=lambda x: x.get_zorder())
TypeError: 'PathCollection' object is not iterable
【问题讨论】:
-
@Anwarvic 该帖子可能不相关。当我尝试制作动画时出现错误。我处理了帖子引用的多次退货问题。
-
这能回答你的问题吗? How to animate a scatter plot?
-
@AnnZen 不直接。我发现了这个问题。如果我设置 blit=True 动画不起作用并且我得到错误。没有参数,动画就可以工作。有人可以解释一下该参数在做什么。 .
-
我认为这是您问题的答案:stackoverflow.com/questions/35068396/…
标签: python matplotlib animation scatter-plot