def __init__(self, var_xarray, Nsteps, vmin, vmax, animationname):
# Global definitions
self.var = var_xarray
self.Nsteps = Nsteps
self.vmin = vmin
self.vmax = vmax
# Figure and axes
self.fig = plt.figure(figsize=(8,3))
self.ax=plt.axes(projection=ccrs.PlateCarree())
self.ax.set_extent([-90, 15, 25, 70],ccrs.PlateCarree())
self.plt_hdl = self.var[0, ...].plot.pcolormesh('nav_lon','nav_lat',ax=self.ax,
vmin=self.vmin, vmax=self.vmax,
transform=ccrs.PlateCarree())
plt.title(self.var[0, ...].coords['time_centered'].values, size=10) # to modify the title
#self.ax.title.set_size(10)
lon_tcks = range(-80,20,20)
lat_tcks = range(30,70,10)
self.ax.set_xticks(lon_tcks, crs=ccrs.PlateCarree())
self.ax.set_yticks(lat_tcks, crs=ccrs.PlateCarree())
self.ax.coastlines(resolution='50m') # Currently can be one of “110m”, “50m”, and “10m”
self.ax.gridlines()
# Animation definitio
anim = animation.FuncAnimation(self.fig, self.update, xrange(Nsteps), interval=1, blit=False)
# Writer FFMpeg needed for mp4 film
mywriter = animation.FFMpegWriter(bitrate=500)
anim.save(animationname, writer=mywriter, fps=1, extra_args=['-vcodec', 'libx264'], dpi=300)
#anim.save(animationname, writer=mywriter, fps=1, extra_args=['-vcodec', 'libx264'])
# No init_plot needed
评论列表
文章目录