On Tuesday, June 7, 2011, Bruce Ford <br...@clearscienceinc.com> 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? > > 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" > 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() > > --------------------------------------- > Bruce W. Ford > Clear Science, Inc. > br...@clearscienceinc.com > http://www.ClearScienceInc.com > http://www.facebook.com/clearscience > http://www.twitter.com/ROVs_rule > Phone: (904) 796-8101 > Fax: (904) 379-9704 > 8241 Parkridge Circle N. > Jacksonville, FL 32211 > Skype: bruce.w.ford > >
I would double-check the shapes of x1 and y1 to make sure it matches t2m's shape. You shouldn't need another Basemap object. Ben Root ------------------------------------------------------------------------------ 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