|
From: Jeff W. <jef...@no...> - 2012-08-20 22:29:14
|
On 8/20/12 4:41 PM, Scott Henderson wrote: > I'm having trouble with transform_scalar() and imshow() with basemap. > Essential I have data from satellite tracks that are either smaller or > larger than the map extent, so I don't want to use Basemap.imshow() > which sets the 'extent' keyword automatically. > > I tried following the following suggestion, but I can't get things to > line up.. > http://comments.gmane.org/gmane.comp.python.matplotlib.general/25085 > > I suspect I've done something wrong in the code below?: Scott: If you use the pcolormesh or contourf Basemap methods (instead of imshow), you can specify the map projection coordinates of your data and it will be plotted correctly (whether or not it covers the whole map projection region). -Jeff > > > # ------------------------------- > from mpl_toolkits.basemap import Basemap > import matplotlib.pyplot as plt > > LL = (-68, -26) > UR = (-66, -21) > bmap = Basemap(projection='merc', > llcrnrlat=LL[1], > urcrnrlat=UR[1], > llcrnrlon=LL[0], > urcrnrlon=UR[0], > resolution='i', > suppress_ticks=False, > ax=ax) > bmap.drawcountries(linewidth=1) > > # Overlay image with extents that don't match map boundaries > nLon, nLat = image.shape > LL = (-69.915, -31.161) > UR = (-65.075, -17.334) > dy = -0.006666664 > lats = UR[1] + dy * np.arange(nLat) > extent = (LL[0], UR[0], LL[1], UR[1]) > nx = nLon; ny = nLat > image_xy = bmap.transform_scalar(image, lons, lats[::-1], nx, ny) > x, y = bmap(extent[:2],extent[2:]) > extent_xy = (x[0], x[1], y[0], y[1]) > im = plt.imshow(image_xy, extent=extent_xy) > > > > -- > --------------- > Scott T. Henderson > http://www.geo.cornell.edu/eas/gstudent/sth54/contact.html > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Jeffrey S. Whitaker Phone : (303)497-6313 Meteorologist FAX : (303)497-6449 NOAA/OAR/PSD R/PSD1 Email : Jef...@no... 325 Broadway Office : Skaggs Research Cntr 1D-113 Boulder, CO, USA 80303-3328 Web : http://tinyurl.com/5telg |