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




On Tue, Jun 7, 2011 at 1:06 AM, Benjamin Root <ben.r...@ou.edu> wrote:

> On Monday, June 6, 2011, Bruce Ford <br...@clearscienceinc.com> wrote:
> > Does anyone have an example of nested grids.
> > I need to (for instance), plot a global grid in filled contours, then
> plot another, higher resolution grid over the US.The global grid could work
> something like this, but I'm not sure where to start with the 2nd (nested)
> grid to go atop.
> >
> >
> > fig=plt.figure()m =
> Basemap(resolution='c',projection='cyl',llcrnrlon=lon1,llcrnrlat=lat1,\
>       urcrnrlon=lon2,urcrnrlat=lat2)# make a filled contour plot.
> >
> > x, y = m(lons, lats)CS =
> m.contour(x,y,hgt,15,linewidths=0.5,colors='k')CS =
> m.contourf(x,y,hgt,15,cmap=plt.cm.jet)m.drawcoastlines()m.drawmapboundary()
> > m.fillcontinents()
> > # draw parallels and meridians.parallels =
> np.arange(-90,90,10)#m.drawparallels(parallels,labels=[1,0,0,1])m.drawparallels(parallels,labels=[1,0,0,1])meridians
> = np.arange(-180.,180.,10.)
> >
> > m.drawmeridians(meridians,labels=[1,0,0,1])plt.title('Plotted
> Grid')plt.show()
> > Thanks!
> > Bruce
> > ---------------------------------------
> > Bruce W. Ford
> > Clear Science, Inc.
> > br...@clearscienceinc.com
> >
> >
> >
> >
> >
>
> It should just work as you expect.  Do the global contour with the
> coarser x/y data, and then do the US contour with finer x/y data.
>
> 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

Reply via email to