Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot city names for lon,lat coordinates

I want to plot the names of cities onto a map of germany using the Basemap package. I have specified the longitude and latitide values with:

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

furthermore,

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 plot the city names but it isnt working but returns the exception

ValueError: object too deep for desired array

like image 668
2Obe Avatar asked Jun 24 '17 09:06

2Obe


1 Answers

You have to plot city names and markers for it in a cycle:

...
# 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)
...
like image 191
Serenity Avatar answered Sep 18 '22 23:09

Serenity