Skip to content

Instantly share code, notes, and snippets.

@turnersr
Created September 28, 2014 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turnersr/e9933274407c5079a3c2 to your computer and use it in GitHub Desktop.
Save turnersr/e9933274407c5079a3c2 to your computer and use it in GitHub Desktop.
Create temperate over time animation. Example at https://vimeo.com/107410270
from iris import load_cube
import iris.quickplot as qplt
import matplotlib.pyplot as plt
from matplotlib import animation
import sys
# air_temp_location is the directory with your air.sig995 netCDF files
air_temp_location = ""
date = range(1948,2015)
def plot_year(i):
plt.gcf().clf()
year = date[i]
fileout = 'air.sig995.'+ str(year) + '.nc'
temperature = load_cube(air_temp_location + fileout)
cont = qplt.contourf(temperature[0,:,:])
gca().coastlines()
plt.title('{0} Mean Daily Air Temperature at Sigma Level 995'.format(year))
return cont
fig = plt.figure()
anim = animation.FuncAnimation(fig, plot_year,
frames=len(date))
anim.save('air_temperature_over_time.mp4', fps=5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment