matplotlib 如何设置散点标记的动画和更新其大小

i34xakig  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(99)

我有两个数据集,点和Pointsize。我想动画的坐标(点)和大小的变化图(Pointsize)的点。但我只能更新点。下面的代码显示,三个点移动的数据点的变化。我想要的是,点不仅移动,但也改变其大小。我试图使用scat.set_offsets(Points 'xy '],Pointsize)来实现我的目标。但是错误显示“TypeError:set_offsets()takes exactly 2 arguments(3 given)"。我还尝试使用重复的set_offsets来分别更新Points 'xy']和Pointsize。错误显示“ValueError:total size of new array must be unchanged”。
我不知道如何解决这个问题。有人能告诉我一个方法或解决方案来实现我的目标吗?我将感谢你的帮助。非常感谢。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

def updata(frame_number):
    current_index = frame_number % 3
    a = [[10,20,30],[40,50,60],[70,80,90]]
    Points['xy'][:,0] = np.asarray(a[current_index])
    Points['xy'][:,1] = np.asarray(a[current_index])
    Pointsize = a[current_index]
    scat.set_offsets(Points['xy'])
    #scat.set_offsets(Pointsize)
    #scat.set_offsets(Points['xy'],Pointsize)
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    ax.set_title("For Dataset %d" % current_index)

fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)
Points = np.zeros(3,dtype=[('xy',float,2)])
Pointsize = [10] * 3
scat = ax.scatter(Points['xy'][:,0],Points['xy'][:,1],s=Pointsize,alpha=0.3,edgecolors='none')
ax.set_xlim(0,100)
ax.set_ylim(0,100)
animation = FuncAnimation(fig,updata,frames=50,interval=600)
plt.show()

字符串

4ioopgfo

4ioopgfo1#

rain simulation example中所示,使用.set_sizes

scat.set_sizes(Pointsize)

字符串
更新散点的大小

相关问题