Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

python - Coordinates on basemap seems to be at 0,0

I am trying to plot some longitudal and latitudal coordinates on a map with basemap. The code I am running is:

m = Basemap(projection='merc', resolution='i',
            llcrnrlat=min_lat - 3, urcrnrlat=max_lat + 3,
            llcrnrlon=min_long - 3, urcrnrlon=max_long + 3)
m.drawcoastlines()
m.fillcontinents(color="#FFDDCC", lake_color='#DDEEFF')
m.drawmapboundary(fill_color='#DDEEFF')
m.drawcountries(linewidth=1)
for coordinates in locations:
    m.scatter(coordinates[1], coordinates[0], marker='D', color='m')

plt.show()

where:

min_lat, min_long, max_lat, max_long = 48.9810946, -0.014840257753543178, 60.448137, 24.9362469

and the coordinates in this setup, i.e. locations (that is plotted via the for loop) are these six:

[55.663457, 12.34772]
[53.5797869, 10.0131747]
[53.549816899999996, 10.048393278279384]
[52.3353336, 4.9294416]
[51.5118813, -0.0010296]
[51.5118813, -0.0010296] 

The result is:

enter image description here

and as you may be able to see there are some purple in the lower-left corner, which I'm guessing is all the points wrapped up in the same point.

I have tried to make the map bigger, but that results in the same, and I also tried to switch between m.scatter(coordinates[1], coordinates[0], marker='D', color='m') and m.scatter(coordinates[0], coordinates[1], marker='D', color='m') with the same result.

What am I doing wrong here? (and yes, this is my first time with basemap, so bear with me).

question from:https://stackoverflow.com/questions/65888432/coordinates-on-basemap-seems-to-be-at-0-0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Rearange your date and call your Basemap object m() to calculate the map projection coordinates.

lons = [12.34772, 10.0131747, 10.048393278279384, 4.9294416, -0.0010296, -0.0010296]
lats = [55.663457, 53.5797869, 53.549816899999996, 52.3353336, 51.5118813, 51.5118813]

x, y = m(lons, lats)

m.scatter(x, y, marker='D',color='m')

Here is a tutorial.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...