2017-08-04 12 views
1

basemapdrawgreatcircle関数を使用しようとしています。ラインにエンドキャップの矢頭を付ける方法はありますか?Pythonのベースマップ:矢印のエンドキャップ付きの円を描く

私はmatplotlibのドキュメントから、引数としてmatplotlibオプションを渡すことができます。 solid_capstyleはエンドキャップを変更しますが、矢印はこれのオプションではありません。

EDIT:@swatchaiからリクエストされたとおり、私は何をしたいのかを示すコードを投稿しました。 solid_capstyle = 'arrow'は有効なオプションではないため、エラーになります。それが機能していないため、これが「最善の試行」の要件を満たしているかどうかは不明です。

from mpl_toolkits.basemap import Basemap 
import numpy as np 
import matplotlib.pyplot as plt 
# create new figure, axes instances. 
fig=plt.figure() 
ax=fig.add_axes([0.1,0.1,0.8,0.8]) 
# setup mercator map projection. 
m = Basemap(llcrnrlon=-100.,llcrnrlat=20.,urcrnrlon=20.,urcrnrlat=60.,\ 
      rsphere=(6378137.00,6356752.3142),\ 
      resolution='l',projection='merc',\ 
      lat_0=40.,lon_0=-20.,lat_ts=20.) 
# nylat, nylon are lat/lon of New York 
nylat = 40.78; nylon = -73.98 
# lonlat, lonlon are lat/lon of London. 
lonlat = 51.53; lonlon = 0.08 
# draw great circle route between NY and London 
m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b', solid_capstyle='arrow') 
m.drawcoastlines() 
m.fillcontinents() 
# draw parallels 
m.drawparallels(np.arange(10,90,20),labels=[1,1,0,1]) 
# draw meridians 
m.drawmeridians(np.arange(-180,180,30),labels=[1,1,0,1]) 
ax.set_title('Great Circle from New York to London') 
+0

「最善の試行」コードを投稿してください。これにより、より多くのチャンスが得られます。私はすでに私の心に一つ持っています。 – swatchai

+0

コードが追加されました。それが答えの可能性を高めるのに十分なのかどうかは分かりません。 – AnonymousCowherd

答えて

0

これは回避策です。大円の一端に注釈(空白のテキスト付き)を描きます。注釈には、必要な場所に配置する必要がある矢印が付いています。

from mpl_toolkits.basemap import Basemap 
import numpy as np 
import matplotlib.pyplot as plt 

# create new figure, axes instances. 
fig=plt.figure(figsize=(12,7)) 
ax=fig.add_axes([0.1,0.1,0.8,0.8]) 

# setup mercator map projection. 
m = Basemap(llcrnrlon=-100.,llcrnrlat=20.,urcrnrlon=20.,urcrnrlat=60.,\ 
      rsphere=(6378137.00,6356752.3142),\ 
      resolution='l',projection='merc',\ 
      lat_0=40.,lon_0=-20.,lat_ts=20.) 
# nylat, nylon are lat/lon of New York 
nylat = 40.78; nylon = -73.98 
# lonlat, lonlon are lat/lon of London. 
lonlat = 51.53; lonlon = 0.08 

# draw great circle route between NY and London 
# m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b', solid_capstyle='arrow') 

# ============= 
# begin my code 
# ------------- 

# grab the great circle, assign a variable for it 
gcline, = m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b') 
path = gcline.get_path() # get path from the great circle 

head = m(lonlon,lonlat)    # get location of arrow's head (at London) 
tail = path.vertices[-len(path)/6] # get location of arrow's tail 

# draw annotation with arrow in 'red' color 
# blank text is specified, because we need the arrow only 
# adjust facecolor and other arrow properties as needed 
ax.annotate('', 
      xy=(head[0], head[1]), 
      xycoords='data', 
      xytext=(tail[0], tail[1]), 
      textcoords='data', 
      size=22, 
      arrowprops=dict(headwidth=15, \ 
          headlength=25, \ 
          facecolor="red", \ 
          edgecolor="none", \ 
          connectionstyle="arc3, rad=0.001")) 
# ----------- 
# end my code 
# =========== 

m.drawcoastlines() 
m.fillcontinents() 
# draw parallels 
m.drawparallels(np.arange(10,90,20),labels=[1,1,0,1]) 
# draw meridians 
m.drawmeridians(np.arange(-180,180,30),labels=[1,1,0,1]) 
ax.set_title('Great Circle from New York to London') 

plt.show() 

結果のプロットは次のとおりです。 enter image description here

関連する問題