【问题标题】:Mathplotlib update 3dplotMatplotlib 更新图
【发布时间】:2015-01-25 19:37:42
【问题描述】:

我正在尝试对 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.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]

我使用了以下示例:http://matplotlib.org/1.4.2/examples/animation/simple_3danim.html

但似乎 set_data 和 set_3d_properties 无法正常工作。有谁知道我做错了什么?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    问题不在于更新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]) 
    

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 2020-12-28
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-13
      • 2017-03-18
      相关资源
      最近更新 更多