I like using Plotly to create interactive plots and maps straight from Python. I find it more intuitive than Bokeh’s API. When combined with Plotly’s sister library Dash, the pair can be very powerful in creating both interactive and dynamic web based tools and visualizations.
While Bokeh has some native Datashader integration, including in the mapping components, the Plotly Mapbox mapping backend relies on Mapbox’s own image overlay capability to display arbitrary Datashader outputs. Plotly has very helpful documentation and includes this use case as an example.
That example code is shown here along with the output map which looks very cool.
|
|
Although it is not particularly obvious on this scale looking at Manhattan, there is actually a projection problem if you are providing a raster that was “datashaded” in Lat/Lon space to the Mapbox image overlay since Mapbox only supports Web Mercator projections.
Mapbox supports the popular Web Mercator projection, and does not support any other projections. Web Mercator is a nearly conformal projection that is adopted by the vast majority of web maps and its use allows you to combine Mapbox’s maps with other layers in the same projection.
Commonly this projection is referred to as EPSG:900913 or EPSG:3857.
The problem becomes much more apparent when trying to plot continuous fields on larger scales. Here is some code that demonstrates the projection problem with this original approach.
|
|
It is clear from the coastline misalignment that there is a projection problem, yet the corners of the plotted ice concentration data still correspond to the “coordinates” input parameter. One solution to this problem is to project the Lat/Lon data into Web Mercator before passing along to Datashader. Even for regular evenly spaced grids this necessarily forces the data to a 2D meshgrid in the projected space, and as a result the Datashader quadmesh transform must be used.
|
|
By combining this projection step to the original methodology, the following example does correctly overlay the raster image layer onto the Web Mercator Plotly/Mapbox plot.
|
|
Useful resources: