Matplotlib animated animation with basemap

I am trying to generate a four panel animation of a change in temperature over time. Each of the four panels in the subtitle should be an animated map; the difference between each panel is the data used. I managed to create an animation using one data set (without subtitles) with the following code:

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 = plt.figure()
m = 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.drawparallels(np.arange(-90.,99.,30.), labels=[1,0,0,0])
m.drawmeridians(np.arange(-180.,180.,60.), labels=[0,0,0,1])
m.drawcoastlines(linewidth=0.25)
m.pcolormesh(lons,lats,y[0],cmap=plt.cm.bwr, shading='flat',latlon=True)

def init():
    m                                                                                                                                                                                                                                                                                                 

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

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

anim.save('movie.mp4')

I have reviewed numerous examples ( 1 , 2 , 3 ), but still do not know how to do this with Basemap.

+4
source share
1 answer

.

  • :

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

. 2x2, 2- , ax[0][0], ax[0][1], ax[1][0] ax[1][1].

+1

Source: https://habr.com/ru/post/1614004/


All Articles