How to plot (lat, lon, value)
data on a map using satellite background images at high resolution in python (notebooks)?
I was crawling the whole internet but could not find anything useful. Folium does not provide satellite tiles. SimpleKML and googleearthplot seem only to be useful for huge low-resolution Earth data. EarthPy can accept image tiles, but their link to the NASA website only provides low-resolution images >0.1 deg. Cartopy is the new hope for matplotlib users, but I cannot find any example for satellite image tiles.
The frustration is particularly big as this job is super easy with R
, using the RGoogleMaps package, e.g.:
plotmap(lat, lon, col=palette(value), data=mydataframe, zoom = 17, maptype="satellite")
An alternative option is to use
gmplot
. It is basically a python wrapper around the Google Maps javascript API that allows you to generate.html
files that render your plots with the map in the background.Here I use it to plot a random walk against a satellite image background (this map type is not supported by default, but it's pretty straightforward to make it work):
You can open the resulting
.html
file in a browser and interact like you would with Google Maps. Unfortunately, this means you won't get a nicematplotlib
graph window or anything, so in order to generate an image file you'd need to either take a screenshot yourself or hack something to render the HTML for you.Another thing to keep in mind is that you will probably need a Google Maps API key, otherwise you will end up with an ugly darkened watermarked map like I did:
Also, since you want to depict values as colors, you'd need to convert these into color strings by hand and use the
gmap.scatter()
method. If you are interested in this approach let me know so I can try to come up with some code to do that.Update
Here is a version that supports encoding values as colors in the scatter plot over the satellite images. To achieve the effect I use
matplotlib
's colormaps. You can change the colormap if you want, see a list of options here. I also included some code to read the API key from the fileapikey.txt
, which allows each of the researchers to use their own individual key without changing the code (if no such file is found, defaults to no API key as usual).As an example I use a series of monotonically increasing values, which are nicely mapped from a shade of blue to red in the
coolwarm
colormap: