我想使用Basemap包将城市名称绘制到德国地图上。 我已经用:
指定了经度和latitide值Cname=Form_Cities["name"].values
Clat=Form_Cities["lat"].values
Clon=Form_Cities["lon"].values
此外,
map=Basemap(projection="lcc",resolution="l",width=1E6,height=1E6,lon_0=9.9167,lat_0=51.5167,fix_aspect=False)#Resturn just the empty "figure with no conotents on it
map.shadedrelief()
map.drawcountries(color="black",zorder=1,linewidth=1)
和:
ax.annotate(s=Cname,xy=(Clon,Clat),xycoords="axes pixels")
我想绘制城市名称,但它不起作用但返回异常
ValueError:对象太深,不适合所需的数组
答案 0 :(得分:3)
您必须在一个周期中为其绘制城市名称和标记:
...
# convert your coords to map projection coords
yp,xp = map(yp,xp)
map.plot(xp, yp, 'ro', markersize=4) # plot markers
for label, xpt, ypt in zip(point_lables, xp, yp): # add annotation (city names)
plt.text(xpt+0.5, ypt+0.01, label, color='firebrick', fontsize=7)
...
答案 1 :(得分:2)
我已经解决了这个问题:
x,y=map(Clon,Clat)
[ax.annotate(s=nme,xy=(xp,yp),color="gray",alpha=0.5,fontsize=6) for nme,xp,yp in zip(Cname,x,y)
但我仍然不明白为什么我必须用map(Clon,Clat)转换x和y坐标,因为实际上Clon和Clat必须代表 llcrnrlon左下角的地理经度和 llcrnrlat如果我遵循Basemap方法的语法,左下角的地理纬度值:
mpl_toolkits.basemap.Basemap(llcrnrlon = None,llcrnrlat = None, urcrnrlon = None,urcrnrlat = None,llcrnrx = None,llcrnry = None, urcrnrx = None,urcrnry = None,width = None,height = None,projection ='cyl', resolution ='c',area_thresh =无,rsphere = 6370997.0,ellps =无, lat_ts = None,lat_1 = None,lat_2 = None,lat_0 = None,lon_0 = None, lon_1 =无,lon_2 =无,o_lon_p =无,o_lat_p =无,k_0 =无, no_rot = False,suppress_ticks = True,satellite_height = 35786000, boundinglat = None,fix_aspect = True,anchor ='C',celestial = False, round = False,epsg = None,ax = None)
但我还没有这样做:
Clat=Form_Cities["lat"].values
Clon=Form_Cities["lon"].values
还是我错了?
可以请任何人向我解释这个吗?