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
400 views
in Technique[技术] by (71.8m points)

python - scatter plot data does not appear on continents in 'hammer' basemap

I am attempting to plot a dataset over the 'hammer' basemap using a scatter plot. However, the data points won't plot on top of the continents. I noticed in the matplotlib example, there is also not data on the continents (I assumed this was due to the nature of the example). I'm wondering if I'm doing something wrong, or if data cannot be plotted on top of the continents using 'hammer' by design.

If this is the case, is there an ideal basemap to use to plot scatter plot data over the whole Earth (using a relief map would be great, but I would settle for anything at this point)?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You're probably missing the keyword to interpret lat-lon data as such. From the help for Basemap.scatter:

If latlon keyword is set to True, x,y are intrepreted as longitude and latitude in degrees. Data and longitudes are automatically shifted to match map projection region for cylindrical and pseudocylindrical projections, and x,y are transformed to map projection coordinates. If latlon is False (default), x and y are assumed to be map projection coordinates.

I also needed to increase the z-order to get scatter on top of the continents as well as the oceans.

import time, calendar, datetime, numpy
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# draw map with markers for float locations
m = Basemap(projection='hammer',lon_0=180)
m.drawmapboundary(fill_color='#99ffff')
m.fillcontinents(color='#cc9966',lake_color='#99ffff')

m.scatter([-73.98, 238., 0.08, 0., 116.38],[40.78,47.6,  51.53,0., 39.91],
          latlon=True, # Ta-da!
          marker='o',color='k',
          zorder=10)

plt.title('Hammer projection, data on top',fontsize=12)
plt.show()

enter image description here


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

...