Cartopy - multiple arrows using annotate -
using this solution base, possible create multiple arrows emanating same source different targets? e.g. delhi -> beijing (116.4, 39.9), delhi -> cairo (30.0, 31.2), delhi -> tokyo (35.6, 139.6)?
when repeat code below, first arrow.
#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, )
alternatively, there way put .annotate expression i'm using @ present draw connecting lines. i've tried no avail:
#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(), )
this isn't perfect (in fact, i'd welcome improvements), achieved multiple arrows annotate
.
the theory is: use same source
arrows, alter target
lat-lons
(or more correctly, lon-lat
). seems obvious now.
also, don't use annotate
city names. annotate
seems put name @ start of arrow rather endpoint.
as say, i'd welcome suggestions improvements (incl. labelling).
import matplotlib.pyplot plt import cartopy.crs ccrs import cartopy.feature cfeature 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 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 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 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 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 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()
Comments
Post a Comment