底图上的注释文本位置错误

时间:2016-09-04 05:46:55

标签: annotations matplotlib-basemap scatter

我尝试根据墨卡托投影在每个散点样本位置上注释采样位置名称。我使用采样位置作为具有地图投影坐标的注释位置。但放置注释位置是地图上的错误位置。 防爆。当我在太平洋中注释某些位置时,在日本内陆注释文本。

我的地图如下。 enter image description here

这是我的代码。

from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from matplotlib.patches import Polygon
# 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=120.,llcrnrlat=10.,urcrnrlon=150.,urcrnrlat=44.,\
        rsphere=(6378137.00,6356752.3142),\
        resolution='l',projection='merc',\
        lat_0=20.,lon_0=135.,lat_ts=25)
# nylat, nylon are lat/lon of Guam
nylat = 14; nylon = 140
# lonlat, lonlon are lat/lon of Busan.
lonlat = 35; lonlon = 128

# Draw Background Map
m.bluemarble()
m.drawgreatcircle(nylon,nylat,lonlon,lonlat,linewidth=2,color='b')
m.drawcoastlines()
m.fillcontinents()
# draw parallels
m.drawparallels(np.arange(10,50,10),labels=[1,1,0,1])
# draw meridians
m.drawmeridians(np.arange(120,155,10),labels=[1,1,0,1])
#m.drawmapscale(129, 15, 131, 16, 500, barstyle='fancy') drawing map scale
m.ax = ax
# Draw your dataset
lons = [130, 131, 132, 133]
lats = [21, 22, 23, 24]
Annotes = ['Sample #1', '2', '3', '4']
x, y = m(lons, lats)
#m.scatter(x1,y1,s=sizes,c=cols,marker="o",cmap=cm.cool,alpha=0.7)
m.scatter(x, y, s= 20, marker='*',color='y',alpha=0.7)
plt.annotate(Annotes[0], xy=(1110450, 1147253),xycoords='data',
            xytext=(1110450, 1147253),textcoords='data',
            arrowprops=dict(arrowstyle="->")
            )
ax.set_title('Cruise line from Guam to Busan')
plt.show()

提前致谢。欢迎任何评论!

0 个答案:

没有答案