我试图对散点图进行动画处理,但是遇到了以下错误。之前我已经做过这个,但现在不断重复返回此错误。
ValueError: 'vertices' must be a 2D list or array with shape Nx2
我会在下面附上动画代码。我之前已经让它正常运行过,所以知道它可以工作。
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
import matplotlib.transforms as transforms
XA = np.random.randint(80, size=(1000, 15))
YA = np.random.randint(80, size=(1000, 15))
XB = np.random.randint(80, size=(1000, 15))
YB = np.random.randint(80, size=(1000, 15))
XC = np.random.randint(80, size=(1000, 1))
YC = np.random.randint(80, size=(1000, 1))
fig, ax = plt.subplots(figsize = (10,6))
ax.axis('equal')
'''' Scatter Plot '''
scatter_A = ax.scatter(XA[0], YA[0], c=['blue'], alpha = 0.7, s = 20, edgecolor = 'black', zorder = 2)
scatter_B = ax.scatter(XB[0], YB[0], c=['white'], alpha = 0.7, s = 20, edgecolor = 'black', zorder = 2)
offset = lambda p: transforms.ScaledTranslation(p/82.,0, plt.gcf().dpi_scale_trans)
trans = plt.gca().transData
scatter_C = ax.scatter(XC[0], YC[0], c=['red'], marker = 'o', alpha = 0.7, s = 10, edgecolor = 'black', zorder = 2,transform=trans+offset(+2))
'''Animate Function '''
def animate(i) :
scatter_A.set_offsets([[[[[[[[[[[[[[[XA[0+i][0], YA[0+i][0]], [XA[0+i][1], YA[0+i][1]], [XA[0+i][2], YA[0+i][2]], [XA[0+i][3], YA[0+i][3]], [XA[0+i][4], YA[0+i][4]],[XA[0+i][5], YA[0+i][5]], [XA[0+i][6], YA[0+i][6]], [XA[0+i][7], YA[0+i][7]], [XA[0+i][8], YA[0+i][8]], [XA[0+i][9], YA[0+i][9]], [XA[0+i][10], YA[0+i][10]], [XA[0+i][11], YA[0+i][11]], [XA[0+i][12], YA[0+i][12]], [XA[0+i][13], YA[0+i][13]], [XA[0+i][14], YA[0+i][14]]]]]]]]]]]]]]]])
scatter_B.set_offsets([[[[[[[[[[[[[[[XB[0+i][0], YB[0+i][0]], [XB[0+i][1], YB[0+i][1]], [XB[0+i][2], YB[0+i][2]], [XB[0+i][3], YB[0+i][3]], [XB[0+i][4], YB[0+i][4]],[XB[0+i][5], YB[0+i][5]], [XB[0+i][6], YB[0+i][6]], [XB[0+i][7], YB[0+i][7]], [XB[0+i][8], YB[0+i][8]], [XB[0+i][9], YB[0+i][9]], [XB[0+i][10], YB[0+i][10]], [XB[0+i][11], YB[0+i][11]], [XB[0+i][12], YB[0+i][12]], [XB[0+i][13], YB[0+i][13]], [XB[0+i][14], YB[0+i][14]]]]]]]]]]]]]]]])
scatter_C.set_offsets([[XC[0+i][0], YC[0+i][0]]])
ani = animation.FuncAnimation(fig, animate, np.arange(0,1000),
interval = 100, blit = False)
Writer = animation.writers['ffmpeg']
writer = Writer(fps = 10, bitrate = 8000)
ax.autoscale()
plt.draw()
我正在使用 Anaconda 1.6.4
,Python 3.5
和 Python 5.1.0
运行 Spyder 3.1.2
。
[[[[[[[[[[[[[[
)的目的是什么? - ImportanceOfBeingErnest