Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我正在尝试在matplotlib中制作等高线图动画_Python_Numpy_Matplotlib_Animation_Jupyter - Fatal编程技术网

Python 我正在尝试在matplotlib中制作等高线图动画

Python 我正在尝试在matplotlib中制作等高线图动画,python,numpy,matplotlib,animation,jupyter,Python,Numpy,Matplotlib,Animation,Jupyter,我有16个标题不断变化的等高线图,我只想从16个等高线图创建一个动画 我首先设置了下面的图像和数据,但我在动画部分运气不好。 我试图遵循这个例子,但我很挣扎: 我在动画部分的尝试: levels = np.arange(-.6,.6,.03) fig, ax = plt.subplots(nrows=4, ncols=4, figsize=(15,10)) #15, 25 p = [ax.contour(data[0],levels=levels)] def update(i):

我有16个标题不断变化的等高线图,我只想从16个等高线图创建一个动画

我首先设置了下面的图像和数据,但我在动画部分运气不好。 我试图遵循这个例子,但我很挣扎:

我在动画部分的尝试:

levels = np.arange(-.6,.6,.03)

fig, ax = plt.subplots(nrows=4, ncols=4, figsize=(15,10)) #15, 25

p = [ax.contour(data[0],levels=levels)]

def update(i):
    for tp in range(16):
        tp.remove()
    p[0] = ax.contour(data[i], levels) 
    t[1:] = t[0:-1]
    t[0] = time.time()
    timelabel.set_text("{:.3f} fps".format(-1./np.diff(t).mean()))  
    return p[0]

ani = matplotlib.animation.FuncAnimation(fig, update, frames=16, 
                                         interval=30, blit=True, repeat=True) ## increasing interval slows it down!
ani.save("test.mp4")
plt.show()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-57-d70067088c5b> in <module>
      3 fig, ax = plt.subplots(nrows=4, ncols=4, figsize=(15,10)) #15, 25
      4 
----> 5 p = [ax.contour(data[0],levels=levels)]
      6 
      7 def update(i):

AttributeError: 'numpy.ndarray' object has no attribute 'contour'
levels=np.arange(-6.6.03)
图,ax=plt.子批次(nrows=4,ncols=4,figsize=(15,10))#15,25
p=[ax.等高线(数据[0],标高=标高]
def更新(一):
对于范围(16)内的tp:
tp.remove()
p[0]=最大等高线(数据[i],标高)
t[1:]=t[0:-1]
t[0]=time.time()
timelabel.set_text(“{.3f}fps.format(-1./np.diff(t.mean()))
返回p[0]
ani=matplotlib.animation.FuncAnimation(图,更新,帧=16,
间隔=30,blit=真,重复=真)##增加间隔会减慢速度!
ani.save(“test.mp4”)
plt.show()
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在里面
图3,ax=plt.子批次(nrows=4,ncols=4,figsize=(15,10))#15,25
4.
---->5 p=[最大等高线(数据[0],标高=标高]
6.
7 def更新(一):
AttributeError:“numpy.ndarray”对象没有属性“contour”

该错误无法识别轮廓或轮廓。。。如何制作16个等高线图的电影/动画?

这将为您提供一个包含所有子图的阵列:

fig,ax=plt.子批次(nrows=4,ncols=4,figsize=(15,10))#15,25
您必须索引
ax
数组才能在子图形上打印:

#在左上方的子图上绘制
ax[0,0]。等高线(数据[0],标高=标高)
levels = np.arange(-.6,.6,.03)

fig, ax = plt.subplots(nrows=4, ncols=4, figsize=(15,10)) #15, 25

p = [ax.contour(data[0],levels=levels)]

def update(i):
    for tp in range(16):
        tp.remove()
    p[0] = ax.contour(data[i], levels) 
    t[1:] = t[0:-1]
    t[0] = time.time()
    timelabel.set_text("{:.3f} fps".format(-1./np.diff(t).mean()))  
    return p[0]

ani = matplotlib.animation.FuncAnimation(fig, update, frames=16, 
                                         interval=30, blit=True, repeat=True) ## increasing interval slows it down!
ani.save("test.mp4")
plt.show()


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-57-d70067088c5b> in <module>
      3 fig, ax = plt.subplots(nrows=4, ncols=4, figsize=(15,10)) #15, 25
      4 
----> 5 p = [ax.contour(data[0],levels=levels)]
      6 
      7 def update(i):

AttributeError: 'numpy.ndarray' object has no attribute 'contour'