我正在尝试制作散点图的动画,其中点的颜色和大小在动画的不同阶段发生变化.对于数据,我有两个numpy ndarray,x值和y值:
data.shape = (ntime, npoint)
x.shape = (npoint)
y.shape = (npoint)
Run Code Online (Sandbox Code Playgroud)
现在我想绘制一个类型的散点图
pylab.scatter(x,y,c=data[i,:])
Run Code Online (Sandbox Code Playgroud)
并在索引上创建一个动画i.我该怎么做呢?
我一直在试图挽救一个动画散点图与matplotlib,我宁愿它并不需要完全不同的代码查看为动画人物和保存一份副本.该图显示了保存完成后的所有数据点.
此代码是修改后的版本Giggi的在动画中matplotlib 3D散点图,从对颜色的修复晏的回答对Matplotlib三维散彩丢失重绘后(因为颜色将是我的视频很重要,所以我要确保他们的工作).
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
FLOOR = -10
CEILING = 10
class AnimatedScatter(object):
def __init__(self, numpoints=5):
self.numpoints = numpoints
self.stream = self.data_stream()
self.angle = 0
self.fig = plt.figure()
self.fig.canvas.mpl_connect('draw_event',self.forceUpdate)
self.ax = self.fig.add_subplot(111,projection = '3d')
self.ani = animation.FuncAnimation(self.fig, self.update, interval=100,
init_func=self.setup_plot, blit=True,frames=20)
def change_angle(self):
self.angle = (self.angle + 1)%360
def forceUpdate(self, event):
self.scat.changed()
def setup_plot(self):
X = next(self.stream)
c …Run Code Online (Sandbox Code Playgroud)