0

I am trying to plot the location of NYC and Berlin on a basemap with a scatter plot.

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

m = Basemap(projection='robin',lon_0=0,resolution='l')

# New York and Berlin
lats = (13.388889,52.516667)
lons = (-74.0059,40.7127)

m.drawcountries(color='#ffffff', linewidth=0.5)
m.fillcontinents(color='#c0c0c0',lake_color='#ffffff')

x, y = m(lons, lats)  # transform coordinates
plt.scatter(x, y, 10, marker='o', color='Red') 

plt.savefig("filename.svg", figsize=(24,12))
plt.show()

However, only one of the points shows up on the map at the wrong location. enter image description here

Can anyone assisst me and point out why one point shows up at the wrong location and the other dot doe snot show up at all?

1 Answer 1

2

The matter is your coordinate definition. You are mixing longitude and latitude. After checking the coordinates of Berlin and New York, it comes the following definition:

# Berlin & New York
lats = [52.516667, 40.730610 ]
lons = [13.388889, -73.935242]

Here the whole code:

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np

m = Basemap(projection='robin', lon_0=0, resolution='l')

# Berlin & New York
lats = [52.516667, 40.730610 ]
lons = [13.388889, -73.935242]

m.drawcountries(color='#ffffff', linewidth=0.5)
m.fillcontinents(color='#c0c0c0', lake_color='#ffffff')

x, y = m(lons, lats)
plt.plot(x, y, 'bo', color='r', markersize=5)

plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Silly mistake. Thank you for your support! Much appreciated :) Works perfectly fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.