问题:我想使用 matplotlib.patches.ConnectionPatch 连接两个轴,其中一个是 Cartopy 地图投影。
预期:每个轴中的两个纬度/经度坐标应由一条线连接。
结果:线转到地图投影中的 0,0 坐标,而不是定义的纬度/经度。
如果投影是未修改的 cartopy.crs.PlateCarree(),它确实会按预期工作,但任何其他投影(例如 Robinson())或具有备用 central_longitude 的投影不会。
代码:
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import cartopy.crs as ccrs
plt.close('all')
fig = plt.figure()
ax = plt.subplot(projection=ccrs.Robinson())
lon,lat = 145,-30
ax.stock_img()
ax.plot(lon,lat, marker='x', color='r', transform=ccrs.PlateCarree())
ax2 = fig.add_axes([0.1,0.06,0.8,0.1])
ax2.plot(lon,lat,marker='x', color='r')
# line between axes
con = patches.ConnectionPatch(
xyA=(lon,lat),
xyB=(lon,lat),
coordsA='data', coordsB='data', axesA=ax, axesB=ax2, color='r')
ax2.add_artist(con)
plt.show()
aluckdog
largeQ
相关分类