import netCDF4 nc = netCDF4.Dataset('../data/pottmp.2014.1time.nc') nc.variables.keys() pottmp = nc.variables['pottmp'] pottmp.units pottmp.long_name pottmp.shape pottmp.dimensions data = pottmp[0,0] data.shape import matplotlib.pyplot as plt # These two lines are needed to make matplotlib plot figures inline and at a decent size. # They are not needed in scripts. %matplotlib inline plt.rcParams['figure.figsize'] = (12.0, 8.0) # These lines do the actual plotting plt.contourf(data, 20) plt.show() lon = nc.variables['lon'] lat = nc.variables['lat'] lonvals = lon[:] latvals = lat[:] plt.title (pottmp.long_name + ' (' + pottmp.units + ')') plt.xlabel(lon.long_name + ' (' + lon.units + ')') plt.ylabel(lat.long_name + ' (' + lat.units + ')') plt.contourf(lonvals, latvals, data, 20, cmap=plt.get_cmap('YlGnBu_r')) plt.colorbar() plt.show() profile = pottmp[0,:,214,180] depthvar = nc.variables['level'] depthvals = depthvar[:] plt.plot(depthvals, profile) plt.xlabel(depthvar.long_name + ' (' + depthvar.units + ')') plt.ylabel(pottmp.long_name + ' (' + pottmp.units + ')') plt.title('Vertical profile: first attempt') plt.show() plt.plot(profile, depthvals) plt.xlabel(pottmp.long_name + ' (' + pottmp.units + ')') plt.ylabel(depthvar.long_name + ' (' + depthvar.units + ')') plt.gca().invert_yaxis() # Gets the axes of the plot and reverses the y axis plt.title('Vertical profile: this is better') plt.show()