-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsqg_animate.py
43 lines (36 loc) · 1.06 KB
/
sqg_animate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import matplotlib
matplotlib.use('qt4agg')
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from netCDF4 import Dataset
# animate data from netcdf file generated by sqg_run.py
filename = 'sqg_N64_3hrly.nc'
vmin = -25; vmax = 25; levplot = 1
nc = Dataset(filename)
pv_var = nc['pv']
t_var = nc['t']
nsteps = len(t_var)-1
scalefact = nc.f*nc.theta0/nc.g
fig = plt.figure(figsize=(8,8))
fig.subplots_adjust(left=0, bottom=0.0, top=1., right=1.)
nout = 1
def initfig():
global im
ax = fig.add_subplot(111)
ax.axis('off')
pv = scalefact*pv_var[0,levplot,...]
im = ax.imshow(pv,cmap=plt.cm.jet,interpolation='nearest',origin='lower',vmin=vmin,vmax=vmax)
return im,
def updatefig(*args):
global nout
t = t_var[nout]
pv = scalefact*pv_var[nout]
hr = t/3600.
print(hr,pv.min(),pv.max())
im.set_data(pv[levplot])
nout += 1
return im,
# interval=0 means draw as fast as possible
ani = animation.FuncAnimation(fig, updatefig, frames=nsteps, repeat=False,\
init_func=initfig,interval=0,blit=True)
plt.show()