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
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)
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With