|
4 | 4 | # set up orthographic map projection with |
5 | 5 | # perspective of satellite looking down at 50N, 100W. |
6 | 6 | # use low resolution coastlines. |
7 | | -map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l') |
| 7 | +bmap = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l') |
8 | 8 | # draw coastlines, country boundaries, fill continents. |
9 | | -map.drawcoastlines(linewidth=0.25) |
10 | | -map.drawcountries(linewidth=0.25) |
11 | | -map.fillcontinents(color='coral',lake_color='aqua') |
| 9 | +bmap.drawcoastlines(linewidth=0.25) |
| 10 | +bmap.drawcountries(linewidth=0.25) |
| 11 | +bmap.fillcontinents(color='coral',lake_color='aqua') |
12 | 12 | # draw the edge of the map projection region (the projection limb) |
13 | | -map.drawmapboundary(fill_color='aqua') |
| 13 | +bmap.drawmapboundary(fill_color='aqua') |
14 | 14 | # draw lat/lon grid lines every 30 degrees. |
15 | | -map.drawmeridians(np.arange(0,360,30)) |
16 | | -map.drawparallels(np.arange(-90,90,30)) |
| 15 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 16 | +bmap.drawparallels(np.arange(-90,90,30)) |
17 | 17 | # lat/lon coordinates of five cities. |
18 | 18 | lats=[40.02,32.73,38.55,48.25,17.29] |
19 | 19 | lons=[-105.16,-117.16,-77.00,-114.21,-88.10] |
20 | 20 | cities=['Boulder, CO','San Diego, CA', |
21 | 21 | 'Washington, DC','Whitefish, MT','Belize City, Belize'] |
22 | 22 | # compute the native map projection coordinates for cities. |
23 | | -xc,yc = map(lons,lats) |
| 23 | +xc,yc = bmap(lons,lats) |
24 | 24 | # plot filled circles at the locations of the cities. |
25 | | -map.plot(xc,yc,'bo') |
| 25 | +bmap.plot(xc,yc,'bo') |
26 | 26 | # plot the names of those five cities. |
27 | 27 | for name,xpt,ypt in zip(cities,xc,yc): |
28 | 28 | plt.text(xpt+50000,ypt+50000,name,fontsize=9) |
|
33 | 33 | wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons)) |
34 | 34 | mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.) |
35 | 35 | # compute native map projection coordinates of lat/lon grid. |
36 | | -x, y = map(lons*180./np.pi, lats*180./np.pi) |
| 36 | +x, y = bmap(lons*180./np.pi, lats*180./np.pi) |
37 | 37 | # contour data over the map. |
38 | | -cs = map.contour(x,y,wave+mean,15,linewidths=1.5) |
| 38 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
39 | 39 | plt.title('filled continent background') |
40 | 40 |
|
41 | 41 | # as above, but use land-sea mask image as map background. |
42 | 42 | fig = plt.figure() |
43 | | -map.drawmapboundary() |
44 | | -map.drawmeridians(np.arange(0,360,30)) |
45 | | -map.drawparallels(np.arange(-90,90,30)) |
| 43 | +bmap.drawmapboundary() |
| 44 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 45 | +bmap.drawparallels(np.arange(-90,90,30)) |
46 | 46 | # plot filled circles at the locations of the cities. |
47 | | -map.plot(xc,yc,'wo') |
| 47 | +bmap.plot(xc,yc,'wo') |
48 | 48 | # plot the names of five cities. |
49 | 49 | for name,xpt,ypt in zip(cities,xc,yc): |
50 | 50 | plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w') |
51 | 51 | # contour data over the map. |
52 | | -cs = map.contour(x,y,wave+mean,15,linewidths=1.5) |
| 52 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
53 | 53 | plt.title('land-sea mask background') |
54 | | -map.drawlsmask(ocean_color='aqua',land_color='coral') |
| 54 | +bmap.drawlsmask(ocean_color='aqua',land_color='coral') |
55 | 55 |
|
56 | 56 | # as above, but use blue marble image as map background. |
57 | 57 | fig = plt.figure() |
58 | | -map.drawmapboundary() |
59 | | -map.drawmeridians(np.arange(0,360,30)) |
60 | | -map.drawparallels(np.arange(-90,90,30)) |
| 58 | +bmap.drawmapboundary() |
| 59 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 60 | +bmap.drawparallels(np.arange(-90,90,30)) |
61 | 61 | # plot filled circles at the locations of the cities. |
62 | | -map.plot(xc,yc,'wo') |
| 62 | +bmap.plot(xc,yc,'wo') |
63 | 63 | # plot the names of five cities. |
64 | 64 | for name,xpt,ypt in zip(cities,xc,yc): |
65 | 65 | plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w') |
66 | 66 | # contour data over the map. |
67 | | -cs = map.contour(x,y,wave+mean,15,linewidths=1.5) |
| 67 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
68 | 68 | plt.title('blue marble background') |
69 | | -map.bluemarble() |
| 69 | +bmap.bluemarble() |
70 | 70 |
|
71 | 71 | # as above, but use shaded relief image as map background. |
72 | 72 | fig = plt.figure() |
73 | | -map.drawmapboundary() |
74 | | -map.drawmeridians(np.arange(0,360,30)) |
75 | | -map.drawparallels(np.arange(-90,90,30)) |
| 73 | +bmap.drawmapboundary() |
| 74 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 75 | +bmap.drawparallels(np.arange(-90,90,30)) |
76 | 76 | # plot filled circles at the locations of the cities. |
77 | | -map.plot(xc,yc,'wo') |
| 77 | +bmap.plot(xc,yc,'wo') |
78 | 78 | # plot the names of five cities. |
79 | 79 | for name,xpt,ypt in zip(cities,xc,yc): |
80 | 80 | plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w') |
81 | 81 | # contour data over the map. |
82 | | -cs = map.contour(x,y,wave+mean,15,linewidths=1.5) |
| 82 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
83 | 83 | plt.title('shaded relief background') |
84 | | -map.shadedrelief() |
| 84 | +bmap.shadedrelief() |
85 | 85 |
|
86 | 86 | # as above, but use etopo image as map background. |
87 | 87 | fig = plt.figure() |
88 | | -map.drawmapboundary() |
89 | | -map.drawmeridians(np.arange(0,360,30)) |
90 | | -map.drawparallels(np.arange(-90,90,30)) |
| 88 | +bmap.drawmapboundary() |
| 89 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 90 | +bmap.drawparallels(np.arange(-90,90,30)) |
91 | 91 | # plot filled circles at the locations of the cities. |
92 | | -map.plot(xc,yc,'wo') |
| 92 | +bmap.plot(xc,yc,'wo') |
93 | 93 | # plot the names of five cities. |
94 | 94 | for name,xpt,ypt in zip(cities,xc,yc): |
95 | 95 | plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w') |
96 | 96 | # contour data over the map. |
97 | | -cs = map.contour(x,y,wave+mean,15,linewidths=1.5) |
| 97 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
98 | 98 | plt.title('etopo background') |
99 | | -map.etopo() |
| 99 | +bmap.etopo() |
| 100 | + |
| 101 | +# as above, but use etopo image as map background overlaid with |
| 102 | +# land-sea mask image where land areas are transparent (so etopo |
| 103 | +# image shows through over land). |
| 104 | +fig = plt.figure() |
| 105 | +bmap.drawmapboundary() |
| 106 | +bmap.drawmeridians(np.arange(0,360,30)) |
| 107 | +bmap.drawparallels(np.arange(-90,90,30)) |
| 108 | +# plot filled circles at the locations of the cities. |
| 109 | +bmap.plot(xc,yc,'wo') |
| 110 | +# plot the names of five cities. |
| 111 | +for name,xpt,ypt in zip(cities,xc,yc): |
| 112 | + plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w') |
| 113 | +# contour data over the map. |
| 114 | +cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5) |
| 115 | +plt.title('etopo background with oceans masked') |
| 116 | +bmap.etopo() |
| 117 | +bmap.drawlsmask(ocean_color='DarkBlue',land_color=(255,255,255,1)) |
100 | 118 |
|
101 | 119 | plt.show() |
0 commit comments