我正在尝试创建两个底图,其中第二个位于插图内。我可以在第二个底图中绘制得很好,但是填充大小,drawcoastlines和drawstates似乎被忽略,代价是设置插入xlim和ylim。奇怪的是,drawmapboundary工作得很好。如果注释了插入的xlim和ylim参数,则正确绘制底图函数,但mark_inset不在正确的位置。我按照底图(http://basemaptutorial.readthedocs.io/en/latest/locator.html)的例子,尝试将我的地图投影从lcc更改为cyl(如他们的示例中所示)。由于某种原因,绘图线和底图功能正常工作,这使我相信有一些与地图投影相关的错误。任何帮助都会非常感激!
from IPython import get_ipython
get_ipython().magic('reset -sf')
import matplotlib.pyplot as P
from pylab import * ## import scientific database
close("all") ## close all windows
import netCDF4
import numpy as np
from mpl_toolkits.basemap import Basemap
from matplotlib.font_manager import FontProperties
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
# Main Basemap lat/lon boundaries
ll_lon = -131.4
ll_lat = 22.8
ur_lon = -104.1
ur_lat = 44.1
# Center point of map
ref_lat = (ll_lat + ur_lat)/2.
ref_lon = -(abs(ll_lon) + abs(ur_lon))/2.
# Create first Basemap
fig = P.figure(figsize=(20,15))
m = Basemap(llcrnrlon=ll_lon,llcrnrlat=ll_lat,urcrnrlon=ur_lon,urcrnrlat=ur_lat,lon_0=ref_lon,lat_0=ref_lat,projection='lcc',resolution='h')
# Define corners for drawing inner domain
ll_x = 591679.34684650064
ul_x = 594344.51484522165
ll_y = 592839.05223913607
ul_y = 1806478.1475523338
ur_x = 1857338.6486264155
lr_x = 1807752.1722138769
ur_y = 1779256.3653244921
lr_y = 566631.12743243692
# Plot inner domain
m.plot([ll_x,ul_x],[ll_y,ul_y],linewidth=3,color='k')
m.plot([ul_x,ur_x],[ul_y,ur_y],linewidth=3,color='k')
m.plot([ur_x,lr_x],[ur_y,lr_y],linewidth=3,color='k')
m.plot([lr_x,ll_x],[lr_y,ll_y],linewidth=3,color='k')
# Customize map
m.drawmapboundary(fill_color='aqua')
m.fillcontinents(color='coral',lake_color='aqua')
m.drawcoastlines(linewidth=1.5)
m.drawparallels(np.arange(20.,55.,5.),labels=[True,False,False,False],fontsize=18)
m.drawmeridians(np.arange(-145.,-95.,5.),labels=[False,False,False,True],fontsize=18)
m.drawstates(linewidth=1.0)
m.drawcountries(linewidth=1.0)
##################################
########## Add inset #############
##################################
# Define new axis for inset
ax = fig.add_subplot(111)
axins = zoomed_inset_axes(ax, 5, loc=4)
# Secondary Basemap lat/lon boundaries
ll_lata = 33.374725341796875
ur_lata = 35.076236724853516
ll_lona = -121.02678680419922
ur_lona = -118.92620086669922
# Center point of map
ref_lat = (ll_lata + ur_lata)/2.
ref_lon = -(abs(ll_lona) + abs(ur_lona))/2.
# Create second Basemap
m2 = Basemap(llcrnrlon=ll_lona,llcrnrlat=ll_lata,urcrnrlon=ur_lona,urcrnrlat=ur_lata,lon_0=ref_lon,lat_0=ref_lat,ax=axins)
# Define corners for drawing inner domain
ll_x = 1180454.8544887367
ul_x = 1181076.4843945887
ll_y = 1172180.6247499525
ul_y = 1202324.6929654693
ur_x = 1245128.2633578097
lr_x = 1244450.5310503689
ur_y = 1200944.1870238895
lr_y = 1170801.3279816376
# Plot inner domain
m2.plot([ll_x,ul_x],[ll_y,ul_y],linewidth=3,color='k')
m2.plot([ul_x,ur_x],[ul_y,ur_y],linewidth=3,color='k')
m2.plot([ur_x,lr_x],[ur_y,lr_y],linewidth=3,color='k')
m2.plot([lr_x,ll_x],[lr_y,ll_y],linewidth=3,color='k')
# Define inset parameters
mark_inset(ax,axins,loc1=1,loc2=3,lw=2,fc="none")
# Set xlim and ylim for mark_inset
ll_x = 1114487.9924679566
ul_x = 1117995.9771456306
ll_y = 1094044.0480909257
ul_y = 1283251.5520485893
ur_x = 1311637.0004658864
lr_x = 1306989.5479092139
ur_y = 1279078.0132717683
lr_y = 1089895.0682288238
axins.set_xlim((ll_x+ul_x)/2.,(lr_x+ur_x)/2.)
axins.set_ylim((ll_y+lr_y)/2.,(ul_y+ur_y)/2.)
# Customize map --> this appears to be ignored with the exception of drawmapboundary
m2.drawmapboundary(fill_color='aqua')
m2.fillcontinents(color='coral',lake_color='aqua')
m2.drawcoastlines(linewidth=1.5)
m2.drawstates(linewidth=1.0)
P.show()