import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
np.random.seed(19680801)
fig, ax = plt.subplots()
x, y, s, c =[],[],[],[]
sc = ax.scatter(x,y,s,c=c)
plt.xlim(0,10)
plt.ylim(0,10)defanimate_append(i):
x.append(np.random.rand(1)*10)
y.append(np.random.rand(1)*10)
s.append(np.random.rand(1)*100)
c.append(np.random.rand(1))# set x and y
sc.set_offsets(np.c_[x,y])# set size
sc.set_sizes(np.array(s).ravel())# set color
sc.set_array(np.array(c).ravel())defanimate(i):
x.clear()
y.clear()
s.clear()
c.clear()
x.append(np.random.rand(1)*10)
y.append(np.random.rand(1)*10)
s.append(np.random.rand(1)*100)
c.append(np.random.rand(3,))# set x and y
sc.set_offsets(np.c_[x, y])# set size
sc.set_sizes(np.array(s).ravel())# set color
sc.set_array(np.array(c).ravel())
ani = matplotlib.animation.FuncAnimation(fig, animate,
frames=2, interval=1000, repeat=True)
plt.show()
说在前面python版本:3.7matploylib版本:3.4.2环境:win10场景实时更新数据,可重绘代码import matplotlib.pyplot as pltimport matplotlib.animationimport numpy as npnp.random.seed(19680801)fig, ax = plt.subplots()x, y, s, c = [],[],[],[]sc = ax.scatter(x,y,s,c=c)plt.