On 06/07/2011 11:36 AM, Bruce Ford wrote: > That's what I thought, but the code below fails (ValueError: Shape > mismatch objects cannot be broadcast to a single shape) when trying to > plot the 2nd parameter. Do I need another basemap?
No, but check the dimensions of t2m; maybe it is transposed relative to what is needed. It needs to have shape (n_latitudes, n_longitudes), just like x1 and y1. It's confusing, but it's a common convention. Also, although this is not relevant to your particular problem here, it might be good to transform your lon, lat 2-D arrays into map coordinates, so that if you decide to use a different projection some day, it will still work. Eric > > Appreciate any thoughts! > > from mpl_toolkits.basemap import Basemap, shiftgrid > from netCDF4 import Dataset > import numpy as np > import matplotlib.pyplot as plt > > fig=plt.figure() > lon1 = 0 > lon2 = 357.5 > lat1 = -90 > lat2 = 90 > m = Basemap(resolution='c',projection='cyl',llcrnrlon=lon1,llcrnrlat=lat1,\ > urcrnrlon=lon2,urcrnrlat=lat2) > > #get data and plot 1st parameter - This works > filename = "/data/reanal-2/ltm/monthly_ltm_01.nc <http://monthly_ltm_01.nc>" > print filename > nc = Dataset(filename, mode="r") > hgt = nc.variables['HGT_2_ISBL_10'][16,:,:] > print hgt.shape > lons = nc.variables['longitude'][:] > lats = nc.variables['latitude'][:] > x,y = np.meshgrid(lons, lats) > CS = m.contour(x,y,hgt,15,linewidths=0.5,colors='k') > CS = m.contourf(x,y,hgt,cmap=plt.cm.jet) > ########################### > > #extract and plot 2nd paramter - This fails with > # ValueError: Shape mismatch objects cannot be broadcast to a single shape > filename1 = "/data/nps_datasets/WNA_T2m_200808.nc" > print filename1 > nc1 = Dataset(filename1, mode="r") > for var in nc1.variables: > print var > t2m = nc1.variables['T2m'][0,:,:] > print t2m.shape > lons1 = nc1.variables['lon'][:] > lats1 = nc1.variables['lat'][:] > x1,y1 = np.meshgrid(lons1, lats1) > CS1 = m.contour(x1,y1,t2m,15,linewidths=0.5,colors='k') > CS1 = m.contourf(x1,y1,t2m,cmap=plt.cm.jet) > ############################# > > m.drawcoastlines() > m.drawmapboundary() > #m.fillcontinents() > # draw parallels and meridians. > parallels = np.arange(-90,90,30) > #m.drawparallels(parallels,labels=[1,0,0,1]) > m.drawparallels(parallels,labels=[1,0,0,1]) > meridians = np.arange(0,357.5,30) > m.drawmeridians(meridians,labels=[1,0,0,1]) > plt.title('Plotted Grid') > plt.show() > ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users