Simon Kammerer wrote:
> Hi list,
>
>
> when using clabel with basemap, it seems to me that clabel labels 
> contours outside the visible area of my maps, (see attached example).
>
> Any hints / workarounds? Or am I missing something?
>
> Regards
> Simon
>
>
>   

Simon:  Yes, that's right - much of the data you are contouring falls 
outside the visible range of your map, and clabel doesn't know that.  
The only workaround I can think of is to only contour the data that's 
within the map you're interested in.  One way to do this would be to 
create a masked array, with all the points outside the map region 
masked. The basemap instance has attributes xmin,xmax,ymin,ymax which 
define the corners of the map in projection coordinates - you can use 
these to determine which points on your grid are outside.  Here's a 
modified version of your example that does this:

from matplotlib.toolkits.basemap import Basemap
import pylab as p
from matplotlib.numerix import ma
map = Basemap(llcrnrlon=-35.,llcrnrlat=25.,urcrnrlon=65.,urcrnrlat=55.,
      
resolution='l',area_thresh=1000.,projection='stere',lat_0=60.,lon_0=0.)
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines()
map.drawcountries()
map.fillcontinents(color='coral')
# draw the edge of the map projection region (the projection limb)
#map.drawmapboundary()
# draw lat/lon grid lines every 30 degrees.
map.drawmeridians(p.arange(0,360,30))
map.drawparallels(p.arange(-90,90,30))
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*p.pi/(nlons-1)
lats = (0.5*p.pi-delta*p.indices((nlats,nlons))[0,:,:])
lons = (delta*p.indices((nlats,nlons))[1,:,:])
wave = 0.75*(p.sin(2.*lats)**8*p.cos(4.*lons))
mean = 0.5*p.cos(2.*lats)*((p.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
x, y = map(lons*180./p.pi, lats*180./p.pi)
mask1 = x < map.xmin
mask2 = x > map.xmax
mask3 = y > map.ymax
mask4 = y < map.ymin
mask = mask1+mask2+mask3+mask4
data = ma.masked_array(wave+mean,mask=mask)
# contour data over the map.
cs = map.contour(x,y,data,15,linewidths=1.5)
p.clabel(cs)
p.show()


-Jeff

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to