matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
779 stars 392 forks source link

Basemap and LightSource #467

Closed dosoe closed 5 years ago

dosoe commented 5 years ago

Hi! I'm trying to overlay a shade of the topography onto my map. Shaderelief doesn't fit my purpose, as it is a map background and has color to it. Matplotlib uses LightSource (https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.colors.LightSource.html?highlight=hillshade#matplotlib.colors.LightSource.hillshade) My attempts revolve around

m = Basemap(llcrnrlon=lonmin,llcrnrlat=latmin,urcrnrlon=lonmax,urcrnrlat=latmax,\
                rsphere=(6378137.00,6356752.3142),\
                resolution='l',projection='laea',\
                lat_0=40.,lon_0=10.,lat_ts=20.)
ls = LightSource(azdeg=315, altdeg=45)
m.imshow(ls.hillshade(grid_z, vert_exag=1), cmap='gray')

for shading (where grid_z is an array of elevations), but I can't make it work with basemap as it will not adapt to the projection, i. e. there is no way that I'm aware of to use the map coordinates in LightSource and its methods. As topography shades is a thing that can be quite useful on a mapping tool, could there be a way to implement it, or is there a way and I'm just not aware of it? I'm using Basemap version 1.2.0

dosoe commented 5 years ago

Hi! It turns out there is an example, it's just not on the website: https://github.com/matplotlib/basemap/blob/master/examples/plotmap_shaded.py