Cartopy-使用注释的多个箭头
使用作为基础,是否可以创建从同一来源到不同目标的多个箭头?e、 德里->北京(116.4,39.9),德里->开罗(30.0,31.2),德里->东京(35.6139.6) 当我重复下面的代码时,我只得到第一个箭头Cartopy-使用注释的多个箭头,cartopy,Cartopy,使用作为基础,是否可以创建从同一来源到不同目标的多个箭头?e、 德里->北京(116.4,39.9),德里->开罗(30.0,31.2),德里->东京(35.6139.6) 当我重复下面的代码时,我只得到第一个箭头 #Dehli - Beijing ax.annotate('Beijing', xy=(116.4, 39.9), xycoords=transform, size=40, ) ax.annotate('Delhi
#Dehli - Beijing
ax.annotate('Beijing', xy=(116.4, 39.9), xycoords=transform,
size=40,
)
ax.annotate('Delhi', xy=(113, 40.5), xytext=(77.23, 28.61),
size=40,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.2",
),
xycoords=transform,
)
#Dehli - Cairo
ax.annotate('Cairo', xy=(-6.26, 53.34), xycoords=transform,
size=40,
)
ax.annotate('Delhi', xy=(113, 40.5), xytext=(77.23, 28.61),
size=40,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.2",
),
xycoords=transform,
)
或者,是否有一种方法将.annotate放入这个表达式中,我目前正在使用它来绘制连接线。我试过了,但没有用:
#Coordinates
lon_dehl, lat_dehl = 116.4, 39.9
lon_beij, lat_beij = 77.59, 12.97
lon_toky, lat_toky = 35.6, 139.6
lon_cair, lat_cair = 30.0, 31.2
plt.plot([lon_dehl, lon_beij], [lat_dehl, lat_beij],
linewidth=2,
linestyle='solid',
solid_capstyle='round',
color='#cb2c31',
marker='o',
markersize=6,
markeredgewidth=None,
markeredgecolor='#cb2c31',
transform=ccrs.PlateCarree(),
)
这不是完美的(事实上,我欢迎任何改进),但我实现了多个箭头
其原理是:对所有箭头使用相同的源
,但改变目标
lat-lons
(或者更准确地说,lon-lat
)。现在看来很明显
另外,不要对城市名称使用注释<代码>注释
似乎将名称放在箭头的开头,而不是终点
正如我所说,我欢迎任何改进建议(包括标签)
这并不完美(事实上,我欢迎任何改进),但我实现了多个箭头
其原理是:对所有箭头使用相同的源
,但改变目标
lat-lons
(或者更准确地说,lon-lat
)。现在看来很明显
另外,不要对城市名称使用注释<代码>注释
似乎将名称放在箭头的开头,而不是终点
正如我所说,我欢迎任何改进建议(包括标签)
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from pyproj import Proj, transform
def main():
ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent([-150, 60, -25, 60])
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS)
#Labels - city locations & names
ax.plot(77.20, 28.61, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(65, 33, 'Dehli', transform=ccrs.Geodetic())
ax.plot(139.69, 35.68, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(139.69, 35.68, 'Tokyo', transform=ccrs.Geodetic())
ax.plot(0.12, 51.50, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(0.12, 51.50, 'London', transform=ccrs.Geodetic())
ax.plot(-71.05, 42.36, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(-71.05, 42.36, 'New York', transform=ccrs.Geodetic())
ax.plot(151.81, -33.86, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(151.81, -33.86, 'Sydney', transform=ccrs.Geodetic())
ax.plot(-43.2, -22.9, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(-43.2, -22.9, 'Rio', transform=ccrs.Geodetic())
#Arrows lines
transform = ccrs.PlateCarree()._as_mpl_transform(ax)
#Dehli to Tokyo
ax.annotate('', xy=(139.69, 35.68), xytext=(77.20, 28.61),
xycoords='data',
size=20,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.3"))
#Dehli to London
ax.annotate('', xy=(0.12, 51.50), xytext=(77.20, 28.61),
size=10,
xycoords='data',
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.3"))
#Dehli to New York
ax.annotate('', xy=(-71.05, 42.36), xytext=(77.20, 28.61),
xycoords='data',
size=30,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.3"))
#Dehli to Sydney
ax.annotate('', xy=(151.81, -33.86), xytext=(77.20, 28.61),
xycoords='data',
size=10,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.3"))
#Dehli to Rio
ax.annotate('', xy=(-43.2, -22.9), xytext=(77.20, 28.61),
xycoords='data',
size=20,
arrowprops=dict(facecolor='red', ec = 'none',
arrowstyle="fancy",
connectionstyle="arc3,rad=-0.3")
)
#plt.tight_layout()
plt.show()
if __name__ == '__main__':
main()