2017-06-26 9 views
0

注釈とテキストの追加についてthe basemap tutorialを読んだ後も、私はまだこれに関するいくつかの問題に取り組んでいます。私が手Basemap - シェイプファイルからのテキストの追加

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

l_one, l_two = 0, 0 

m = Basemap(projection = 'merc', llcrnrlat= -2, urcrnrlat= 52, llcrnrlon= -137,\ 
      urcrnrlon= -58, lat_ts=40,resolution='i') 
m.shadedrelief() 
m.drawcoastlines(linewidth=0.5) 
m.drawcountries(linewidth=0.5) 
m.drawstates(linewidth=0.5) 
m.drawparallels(np.arange(-90, 90, 10), linewidth = 0.2, 
       labels = [True, False, True, False], fontsize = 'x-small') 
m.drawmeridians(np.arange(-180, 180, 10), linewidth = 0.2, 
       labels = [False, False, False, True], fontsize = 'x-small') 

m.readshapefile('/path/to/shapefile', 'shapefile_name') 
shapefile_info = m.readshapefile('/path/to/shapefile', 'shapefile_name') 
for info, shape in zip(m.points_info, m.points): 
    x, y = zip(shape) 
    if info['LABELTYPE'] == 'ONE': 
     m.plot(x, y, c = 'k', ms = 9., ls = "", mew = 1., 
       label = 'Start Point' if l_one == 0 else "_no-legend_") 
     x, y = m(y[0], x[0]) 
     plt.plot(x, y, info['LABELNAME']) 
     l_one += 1 
    if info['LABELTYPE'] == 'TWO': 
     m.plot(x, y, c = 'c', ms = 9., ls = "", mew = 1., 
       label = 'End Point' if l_two == 0 else "_no-legend_") 
     x, y = m(y[0], x[0]) 
     plt.plot(x, y, info['LABELNAME']) 
     l_two += 1 

...以下のコードを使用して

{'LABELTYPE': 'ONE', 'LABELNAME': 'Start Point'} (2274311.7551607937, 759422.9640236866)

{'LABELTYPE': 'TWO', 'LABELNAME': 'End Point'} (1839892.6558604166, 947255.0800333266)

shapefile_info = m.readshapefile('/path/to/shapefile', 'shapefile_name') 
for info, shape in zip(m.points_info, m.points): 
    print info, shape 

シェープファイルを読み込むと(上記のコード付き)の情報をプリントアウトし、私たちは、この出力を取得します次のエラー: Illegal format string "Start Point"; two linestyle symbols

なぜこのエラーが発生しますか?どのようにしてそれを修正して、辞書のテキストをプロットに置くことができるのですか?

答えて

1

(x,y)にテキストを入力する場合は、plt.plot()の代わりにplt.text()を使用します(plotはテキストではなくラインプロットをプロットします)。

plt.text(x, y, text) 

またはこの場合

plt.text(x, y, info['LABELNAME']) 
関連する問題