Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Jose

By: a guest on Mar 2nd, 2009  |  syntax: Python  |  size: 1.39 KB  |  views: 180  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import numpy
  2. from mpl_toolkits.basemap import Basemap
  3. import matplotlib.pyplot as pylab
  4. x_min = 10 ; x_max = 21.
  5. y_min = -20. ; y_max = -10.
  6. lon_box = numpy.array ( [x_min, x_min, x_max, x_max, x_min])
  7. lat_box = numpy.array ( [y_min, y_max, y_max, y_min, y_min])
  8.  
  9.  
  10. fig = pylab.figure(figsize=(8,8),dpi=300,facecolor='white')    
  11. projection_opts={'projection':'merc','lat_ts':0.0, 'resolution':'h'}
  12. ax1 = fig.add_axes([0.1,0.1,0.8,0.8])
  13.  
  14. m = Basemap(ax=ax1,llcrnrlon=x_min, llcrnrlat=y_min,
  15.          urcrnrlon=x_max,urcrnrlat=y_max,  ** projection_opts)
  16. m.bluemarble()   
  17. m.drawcoastlines (linewidth=0.25, color='w')
  18. m.drawcountries(linewidth=0.25, color='w')
  19. fig.canvas.draw()
  20. background = fig.canvas.copy_from_bbox(fig.bbox)
  21.  
  22.  
  23. for i in xrange(5):
  24.  
  25.         lat_box = lat_box + 2.0*i
  26.         fig2 = pylab.figure(figsize=(8,8),dpi=150,facecolor='white')
  27. #       ax1 = fig.add_axes([0.1,0.1,0.8,0.8])
  28.         ax = fig2.add_subplot(111, frameon=False, xticks=[], yticks=[])
  29.         # restore previous background
  30.         ax2 = fig.add_axes([0.15,0.65,0.25,0.25])
  31.         m2 = Basemap(projection='ortho',lon_0=6,lat_0=-12,ax=ax2)
  32.         (x,y) = m2 (lon_box, lat_box)
  33.         m2.drawmapboundary(fill_color='#33339F')
  34.         m2.drawcoastlines(linewidth=0.1)
  35.         m2.fillcontinents(color='chocolate',lake_color='#33339F')
  36.         m2.plot ( x, y, '-r', lw=2)
  37.         fig2.canvas.draw()
  38.         fig2.canvas.restore_region(background)
  39.         fig2.canvas.draw()
  40.         fig2.savefig ("test_%02d.png"%i,dpi=150)