Skip to content

Instantly share code, notes, and snippets.

@dedeco
Forked from oblakeobjet/show_map.py
Created January 5, 2019 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dedeco/5aea5f666b5b090ce0a65dc72d784e0a to your computer and use it in GitHub Desktop.
Save dedeco/5aea5f666b5b090ce0a65dc72d784e0a to your computer and use it in GitHub Desktop.
# More Info: http://davydany.com/post/32287214449/matplotlibs-basemap-plotting-a-list-of-latitude
def show_map(self, a):
# 'a' is of the format [(lats, lons, data), (lats, lons, data)... (lats, lons, data)]
lats = [ x[0] for x in a ]
lons = [ x[1] for x in a ]
data = [ x[2] for x in a ]
lat_min = min(lats)
lat_max = max(lats)
lon_min = min(lons)
lon_max = max(lons)
data_min = min(data)
data_max = max(data)
spatial_resolution = 0.5
fig = plt.figure()
x = np.array(lons)
y = np.array(lats)
z = np.array(data)
xinum = (lon_max - lon_min) / spatial_resolution
yinum = (lat_max - lat_min) / spatial_resolution
xi = np.linspace(lon_min, lon_max + spatial_resolution, xinum) # same as [lon_min:spatial_resolution:lon_max] in matlab
yi = np.linspace(lat_min, lat_max + spatial_resolution, yinum) # same as [lat_min:spatial_resolution:lat_max] in matlab
xi, yi = np.meshgrid(xi, yi)
zi = griddata(x, y, z, xi, yi)
m = Basemap(
projection = 'merc',
llcrnrlat=lat_min, urcrnrlat=lat_max,
llcrnrlon=lon_min, urcrnrlon=lon_max,
rsphere=6371200., resolution='l', area_thresh=10000
)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
lat, lon = m.makegrid(zi.shape[1], zi.shape[0])
x,y = m(lat, lon)
m.contourf(x, y, zi)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment