Advertisement
Guest User

Jose

a guest
Mar 2nd, 2009
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. import matplotlib
  2. matplotlib.use('Agg')
  3. from mpl_toolkits.basemap import Basemap
  4. import matplotlib.pyplot as plt
  5. from numpy import array
  6. x_min = 10 ; x_max = 21.
  7. y_min = -20. ; y_max = -10.
  8. lon_box = array ( [x_min, x_min, x_max, x_max, x_min])
  9. lat_box = array ( [y_min, y_max, y_max, y_min, y_min])
  10. # this example shows how to save a map background and
  11. # reuse it in another figure.
  12.  
  13. # make sure we have all the same properties on all figs
  14. figprops = dict(figsize=(8,6), dpi=100, facecolor='white')
  15.  
  16. # generate the first figure.
  17. fig1 = plt.figure(1,**figprops)
  18. ax1 = fig1.add_axes([0.1,0.1,.8,.8])
  19. # create basemap instance, plot coastlines.
  20. map = Basemap(projection='moll',lon_0=0)
  21. map.drawcoastlines()
  22. #map.drawmapboundary(fill_color='aqua')
  23. map.fillcontinents(color='coral',lake_color='aqua')
  24. ax3 = fig1.add_axes([0.1,0.75,0.25,0.25])
  25. m2 = Basemap(projection='ortho',lon_0=6,lat_0=-12,ax=ax3)
  26. (x,y) = m2 (lon_box, lat_box)
  27. #m2.drawmapboundary(fill_color='#33339F')
  28. m2.drawcoastlines(linewidth=0.1)
  29. m2.fillcontinents(color='chocolate',lake_color='#33339F')
  30. m2.plot ( x, y, '-r', lw=2)
  31. fig1.canvas.draw()
  32. background = fig1.canvas.copy_from_bbox(fig1.bbox)
  33. fig1.savefig('figure1.png', dpi=100)
  34.  
  35.  
  36. # generate the second figure, re-using the background
  37. # from figure 1.
  38. for i in xrange(5):
  39.     fig2 = plt.figure(2,frameon=False,**figprops)
  40.     ax2 = fig2.add_subplot(111, frameon=False, xticks=[], yticks=[])
  41.     #ax2 = fig2.add_axes ([0.1, 0.1, 0.8, 0.8])
  42.     # restore previous background.
  43.     fig2.canvas.restore_region(background)
  44.     # draw parallels and meridians on existing background.
  45.     map.drawparallels(range(-90,90,30))
  46.     map.drawmeridians(range(-180,180,60))
  47.     fig2.savefig('figure%d.png'%(i+2), dpi=100)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement