- Notifications
You must be signed in to change notification settings - Fork 397
/
Copy pathmake_inset.py
32 lines (27 loc) · 1.11 KB
/
make_inset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import (absolute_import, division, print_function)
frommpl_toolkits.basemapimportBasemap
frommpl_toolkits.axes_grid1.inset_locatorimportinset_axes
importmatplotlib.pyplotasplt
frommatplotlib.patchesimportPolygon
# Set up the primary map
fig=plt.figure()
ax=fig.add_subplot(111)
bmap=\
Basemap(projection='lcc',width=6000.e3,height=4000.e3,lon_0=-90,lat_0=40,resolution='l',ax=ax)
bmap.fillcontinents(color='coral', lake_color='aqua')
bmap.drawcountries()
bmap.drawstates()
bmap.drawmapboundary(fill_color='aqua')
bmap.drawcoastlines()
plt.title('map with an inset showing where the map is')
# axes for inset map.
axin=inset_axes(bmap.ax,width="30%",height="30%",loc=4)
# inset map is global, with primary map projection region drawn on it.
omap=Basemap(projection='ortho',lon_0=-105,lat_0=40,ax=axin,anchor='NE')
omap.drawcountries(color='white')
omap.fillcontinents(color='gray') #color = 'coral'
bx, by=omap(bmap.boundarylons, bmap.boundarylats)
xy=list(zip(bx,by))
mapboundary=Polygon(xy,edgecolor='red',linewidth=2,fill=False)
omap.ax.add_patch(mapboundary)
plt.show()