Jesper Larsen wrote:
> Hi matplotlib users,
>
> I have a small web application for calculating tsunami travel times 
> (http://ocean.dmi.dk/apps/tsunami). The application uses matplotlib/basemap 
> for producing contour maps of the tsunami travel times.
>
> To speed up the response time of the application I made a version in which 
> the 
> calculations are performed for every second integer longitude and latitude 
> for calculation windows of 60x60 degrees lon x lat, 90x90, 180x180 and 
> global. This is a lot of plots for which I am making a new Basemap instances 
> for each plot since:
>
> llcrnrlon
> llcrnrlat
> urcrnrlon
> urcrnrlat
>
> differs for each plot. The initialization of the Basemap instances are 
> responsible for the vast majority of the CPU usage in the application.
>
> In converting the application to numpy (from numarray) I was wondering 
> whether 
> I could reduce the plotting time as well. Is it possible to reuse a Basemap 
> instance somehow in my case or is that out of the question?
>
> Regards,
> Jesper
>
>   


Jesper:  Here's a better way, that allows you to label the meridians and 
parallels.  It will only work for projection='cyl', although a similar 
solution could be worked up for 'merc' and 'mill'.

from matplotlib.toolkits.basemap import Basemap
import pylab as p

def resetmapbounds(map,llcrnrlon,llcrnrlat,urcrnrlon,urcrnrlat):
    map.llcrnrlat = llcrnrlat; map.llcrnrlon = llcrnrlon
    map.urcrnrlat = urcrnrlat; map.urcrnrlon = urcrnrlon
    map.llcrnry = map.llcrnrlat; map.llcrnrx=map.llcrnrlon
    map.urcrnry = map.urcrnrlat; map.urcrnrx=map.urcrnrlon
    return map

fig = p.figure()
# create the Basemap instance
map = Basemap()
map.fillcontinents(color='coral')
map.drawparallels(p.arange(-90,91,30),labels=[1,1,1,1])
map.drawmeridians(p.arange(-180,181,30),labels=[1,1,1,1])
#p.savefig('fig1.png')

# resuse the Basemap instance, resetting the lat/lon domain.
# US Domain.
fig = p.figure()
map = resetmapbounds(map,-140,20,-65,55)
map.fillcontinents(color='coral')
map.drawparallels(p.arange(-90,91,10),labels=[1,1,1,1])
map.drawmeridians(p.arange(-180,181,10),labels=[1,1,1,1])
#p.savefig('fig2.png')

# Europe Domain.
fig = p.figure()
map = resetmapbounds(map,-20,30,40,80)
map.fillcontinents(color='coral')
map.drawparallels(p.arange(-90,91,10),labels=[1,1,1,1])
map.drawmeridians(p.arange(-180,181,10),labels=[1,1,1,1])
#p.savefig('fig3.png')
p.show()


HTH,

-Jeff



-- 
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : [EMAIL PROTECTED]
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to