Python netcdf plot data onto grid
<p>I am using Lat, Lon data and would like to average all the sample_data within a grid cell (say 1km x 1km) uniformly across the whole area, and then plot it similar to this post, but with a basemap, I'm a bit stuck where to start: 
<a href="http://stackoverflow.com/questions/25071968/heatmap-with-text-in-each-cell-with-matplotlibs-pyplot/25074150#25074150">Heatmap with text in each cell with matplotlib&#39;s pyplot</a></p>

<p>The code below plots values through each time point, and I'd like to average the data within defined grid squares across the whole data area at each time point, and plot the average value onto the basemap with a grid at set time intervals (ie. make a set of images for a timelapse/movie). </p>

<pre><code>import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from netCDF4 import Dataset
import matplotlib.cm as cm

data = Dataset(netcdf_data,'r')

lat = data.variables['lat'][:]
lon = data.variables['lon'][:]
time = data.variables['time'][:]


fig = plt.figure(figsize=(1800,1200))
m = Basemap(projection='ortho',lon_0=5,lat_0=35,resolution='l')
m.drawcoastlines()


for value in range(0,len(sample_data)):
    m.plot(lat[:,value], lon[:,value], alpha=1, latlon=True)

plt.show()
</code></pre>

<p>Well, you can get the maximum and minimum of latitude and longitude. </p>

<p>And then get the age of <code>sample_data</code> at a particular time <code>t</code> using:</p>

<pre><code>data_within_box = sample_data[minLat:maxLat,minLon:maxLon,:,t]
avg_age = numpy.average(data_within_box) 
</code></pre>

python matplotlib grid netcdf