添加南海脚图实际上就是增加一个地图坐标系(Axesm),在用axesm函数创建地图坐标系的时候可以指定position参数(即位置和大小),第1和第2个参数是坐标系的左下角x, y位置,后两个参数是坐标系的宽度和高度,单位都是Figure的归一化坐标(0 - 1)。由于地图坐标系在Figure缩放时需要保持地图x, y坐标比例不变(地图不发生变形),坐标系具体绘制的位置会随着Figure缩放而变化,需要提前设置好Figure大小,再调整position参数。
脚本程序:
#Set data folders basedir = ‘D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo‘ mapdir = os.path.join(basedir, ‘map‘) #Read shape files bou2_layer = shaperead(os.path.join(mapdir, ‘bou2_4p.shp‘)) bou1_layer = shaperead(os.path.join(mapdir, ‘bou1_4l.shp‘)) river_layer = shaperead(os.path.join(mapdir, ‘rivers.shp‘)) city_layer = shaperead(os.path.join(mapdir, ‘res1_4m.shp‘)) #Plot axesm() geoshow(bou2_layer, edgecolor=‘lightgray‘) geoshow(bou1_layer, facecolor=(0,0,255)) ss = makesymbolspec(‘line‘, {‘value‘:‘Yangtze‘, ‘color‘:(0,255,255), ‘size‘:1}, {‘value‘:‘Huang He‘, ‘color‘:(0,255,255), ‘size‘:1}, field=‘NAME‘) geoshow(river_layer, symbolspec=ss) geoshow(city_layer, facecolor=‘r‘, size=4, labelfield=‘NAME‘, fontname=u‘楷体‘, fontsize=16, yoffset=15) xlim(72, 136) ylim(16, 55) #Add south China Sea sc_layer = shaperead(os.path.join(mapdir, ‘bou1_4l.shp‘)) axesm(position=[0.14,0.18,0.15,0.2], axison=False) geoshow(sc_layer, facecolor=(0,0,255)) xlim(106, 123) ylim(2, 23)
运行结果:
时间: 2024-10-10 20:07:38