查看原始源码
%matplotlib inline
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([60, 145, -10, 55], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.LAND, facecolor='#f0f0f0')
ax.add_feature(cfeature.OCEAN, facecolor='#b3d9ff')
ax.add_feature(cfeature.COASTLINE, linewidth=0.8)
ax.add_feature(cfeature.BORDERS, linewidth=0.8)
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=0.5, color='gray', alpha=0.5,
linestyle='--')
gl.top_labels = False
gl.right_labels = False
gl.xlocator = plt.FixedLocator([60, 80, 100, 120, 140])
gl.ylocator = plt.FixedLocator([-10, 10, 30, 50])
lon_bj, lat_bj = 116.4, 39.9
lon_kl, lat_kl = 101.7, 3.1
ax.plot([lon_bj, lon_kl], [lat_bj, lat_kl], color='blue',
linewidth=2.5, transform=ccrs.Geodetic(), zorder=3)
ax.plot(lon_bj, lat_bj, marker='*', color='red', markersize=14,
transform=ccrs.PlateCarree(), zorder=4)
ax.plot(lon_kl, lat_kl, marker='*', color='red', markersize=14,
transform=ccrs.PlateCarree(), zorder=4)
plt.text(lon_bj + 1.5, lat_bj - 1.5, '北京', fontsize=12,
fontweight='bold', transform=ccrs.PlateCarree(), zorder=5)
plt.text(lon_kl + 1.5, lat_kl - 1.5, '吉隆坡', fontsize=12,
fontweight='bold', transform=ccrs.PlateCarree(), zorder=5)
plt.title('习题3:北京 -> 吉隆坡 航线图', fontsize=14)
plt.show()