我试图创建一个动画使用以下代码,但我不能让它工作。在
def plotSimulation(currentState, startState):
import matplotlib.pyplot as plt
import matplotlib.animation as ani
import numpy as np
import matplotlib.patches as mpatches
import matplotlib.collections as collections
fig1 = plt.figure()
ax = plt.subplot()
numberOfFrames = currentState.shape[2]
frames = []
for frame in np.arange(numberOfFrames):
carPatches = []
for car in range(0, currentState.shape[0]):
carPatches.append(mpatches.Rectangle([currentState[car,0,frame],currentState[car,1,frame]], startState[car, 2], startState[car, 3], angle=startState[car, 4]))
carCollection = collections.PatchCollection(carPatches)
frames.append((carCollection,))
simulationAnimation = ani.ArtistAnimation(fig1, frames, interval=50, repeat_delay=300, blit=False)
plt.show()
我试图从这个例子中复制http://matplotlib.org/examples/animation/basic_example.html
图2显示的动画
但当我尝试运行动画时,我得到:
^{pr2}$
我认为问题是你已经创建了你的} 完成此操作
PatchCollections
,但没有将它们添加到轴上。您应该能够使用^{尝试将
carCollection
附加到frames
的行改为如下内容:相关问题 更多 >
编程相关推荐