2016-07-11 2 views
0

this solution을 기본으로 사용하면 같은 소스에서 다른 타겟으로 나오는 여러 개의 화살표를 만들 수 있습니까? 예 : 델리 -> 베이징 (116.4, 39.9), 델리 -> 카이로 (30.0, 31.2), 델리 -> 도쿄 (35.6, 139.6)? Cartopy - 주석을 사용하는 다중 화살표

나는 아래의 코드를 반복

, 나는 첫 번째 화살표를 얻는다.

#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(), 
     ) 

답변

1

(사실, 나는 어떤 개선을 환영 것),하지만 난 annotate 여러 화살표를 달성 : 나는 아무 소용이 시도했습니다.

이론은 모든 화살표에 대해 source을 동일하게 사용하지만 targetlat-lons (이상 정확하게는 lon-lat)을 변경합니다. 이제는 분명해 보입니다.

또한 도시 이름에는 annotate을 사용하지 마십시오. Annotate은 끝점보다는 화살표의 시작 부분에 이름을 넣는 것처럼 보입니다.

은 내가 개선을위한 제안 환영 것, 말하는 것처럼 (포함한다. 라벨링).

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() 

enter image description here

관련 문제