Python Mathplotlib更新3dplot
我正在尝试对matplotlib.pyplot.plot对象使用“set_data”和“set_3d_properties”方法Python Mathplotlib更新3dplot,python,matplotlib,Python,Matplotlib,我正在尝试对matplotlib.pyplot.plot对象使用“set_data”和“set_3d_properties”方法 import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as p3 import matplotlib.animation as animation class animationObj(object): def __init__(self): self.fig= plt.fig
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
class animationObj(object):
def __init__(self):
self.fig= plt.figure()
self.ax = self.fig.add_subplot(111, projection='3d')
self.plot = []
self.plot.append(self.ax.plot([0], [0], [0], 'bo', markersize=10)[0])
self.ani = animation.FuncAnimation(self.fig, self, frames=range(0,10), interval=50, repeat_delay=1000)
def show(self):
return plt.show()
def __call__(self, i):
self.plot[0].set_data([x[i]], [y[i]])
self.plot[0].set_3d_properties([z[i]], 'z')
return self.plot[0]
我使用了以下示例:
但是,set_数据和set_3d_属性似乎无法正常工作。有人知道我做错了什么吗?问题不在于更新x、y和z数据的代码,而在于第一次创建动画时,为第一个数据集设置了x、y和z轴的范围。因此,设置x、y和z的范围解决了问题:
self.ax.set_xlim([0, 5])
self.ax.set_ylim([0, 5])
self.ax.set_zlim([0, 5])