Names of city-cities for coordinates lon, lat

I want to build city names on a map of Germany using the Basemap package. I specified the longitude and latitide values ​​with:

Cname=Form_Cities["name"].values Clat=Form_Cities["lat"].values Clon=Form_Cities["lon"].values 

Besides,

 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) 

and with:

 ax.annotate(s=Cname,xy=(Clon,Clat),xycoords="axes pixels") 

I want to build city names, but it does not work, but returns an exception

ValueError: object is too deep for the desired array

+5
source share
2 answers

I solved it like this:

 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) 

but I still don’t understand why I need to convert the x and y coordinates with the map (Clon, Clat), because actually Clon and Clat should represent llcrnrlon Lower left angular geographic longitude and llcrnrlat Geographic latitude values ​​of the lower left corner, if I following the syntax of the basemap method:

mpl_toolkits.basemap.Basemap (llcrnrlon = None, llcrnrlat = No, urcrnrlon = None, urcrnrlat = None, llcrnrx = None, llcrnry = None, urcrnrx = None, urcrnry = None, width = None, width = None width = resolution = c, area_thresh = None, rsphere = 6370997.0, ellps = None, lat_ts = None, lat_1 = None, lat_2 = None, lat_0 = None, lon_0 = None, lon_1 = None, lon_2 = None, o_lon_p = None, o_lat_p = None, k_0 = No, no_rot = False, suppress_ticks = True, satellite_height = 35786000, boundinglat = None, fix_aspect = True, anchor = C, celestial = False, round = False, epsg = None, ax = None)

but I did not do this with:

 Clat=Form_Cities["lat"].values Clon=Form_Cities["lon"].values 

or I'm wrong?

Can anyone explain this to me?

+2
source

In the loop you need to draw city names and markers:

 ... # 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) ... 
+3
source

Source: https://habr.com/ru/post/1269177/


All Articles