Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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 如何在Basemap上使用Matplotlib制作动画子地块?_Python_Animation_Matplotlib_Matplotlib Basemap - Fatal编程技术网

Python 如何在Basemap上使用Matplotlib制作动画子地块?

Python 如何在Basemap上使用Matplotlib制作动画子地块?,python,animation,matplotlib,matplotlib-basemap,Python,Animation,Matplotlib,Matplotlib Basemap,我正在尝试制作一个带有时间的双面板动画。我已经找到了一个类似的我想做的,但我不能通过。这是我的密码 import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation from mpl_toolkits.basemap import Basemap #dummy temperature data with 10 time-steps

我正在尝试制作一个带有时间的双面板动画。我已经找到了一个类似的我想做的,但我不能通过。这是我的密码

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.basemap import Basemap

#dummy temperature data with 10 time-steps                                                     
y = np.random.randn(10, 60, 100)

fig, ax = plt.subplots(1,2)

ax[0].set_title("aaaa")
m_a = Basemap(projection='kav7',lon_0=0)
lats = np.linspace(90,-90,y.shape[1])
lons = np.linspace(-180,180,y.shape[2])
lons, lats = np.meshgrid(lons,lats)

m_a.drawparallels(np.arange(-90.,99.,30.), labels=[1,0,0,0])
m_a.drawmeridians(np.arange(-180.,180.,60.), labels=[0,0,0,1])
m_a.drawcoastlines(linewidth=0.25)
m_a.pcolormesh(lons,lats,y[0],cmap=plt.cm.bwr, shading='flat',latlon=True)

ax[1].set_title("bbbb")
m_b = Basemap(projection='kav7',lon_0=0)
lats = np.linspace(90,-90,y.shape[1])
lons = np.linspace(-180,180,y.shape[2])
lons, lats = np.meshgrid(lons,lats)

m_b.drawparallels(np.arange(-90.,99.,30.), labels=[1,0,0,0])
m_b.drawmeridians(np.arange(-180.,180.,60.), labels=[0,0,0,1])
m_b.drawcoastlines(linewidth=0.25)
m_b.pcolormesh(lons,lats,y[0],cmap=plt.cm.bwr, shading='flat',latlon=True)


def init():
    fig

def animate(i):
    m_a.pcolormesh(lons,lats,y[i],cmap=plt.cm.bwr,shading='flat',latlon=True)
    m_b.pcolormesh(lons,lats,y[i],cmap=plt.cm.bwr,shading='flat',latlon=True)
    return m_a, m_b

anim = animation.FuncAnimation(fig, animate, init_func=init, frames=10, interval=100) #interval = number of milliseconds between frames                                                      

plt.show()

但是,结果动画就在这里⇒. 为什么会这样?如果您查看代码,我很高兴。

我想您只是忘了指定要居住的轴或底图

m_a = Basemap(projection='kav7',lon_0=0, ax=ax[0])
# ...
m_b = Basemap(projection='kav7',lon_0=0, ax=ax[1])

为什么会发生什么?有什么问题吗?我想在Basemap上制作一个两个面板的动画子地块。我的代码在图形的右侧提供了一个动画绘图,但它无法在图形的左侧提供动画。这就是问题所在,我想知道如何解决它。此注释比当前问题中的任何文本都更具信息性。为什么不把它添加到问题中而不是一个评论呢?很抱歉把你弄糊涂了。我会注意的。@importanceofbeingems非常感谢你帮了我的忙。我可以做我想做的事。