pythonbokehholoviewsdatashadergeoviews

Holoviews combined with geoviews.tile_sources causes axis scale error


I'm trying to combine a geoviews.tile_sources layer with a datashade layer. Both layers individually result in the correct axis (see image), but when combined (using *) the scale becomes distorted.

import numpy as np
import pandas as pd
import holoviews as hv
from geoviews.tile_sources import EsriImagery
from holoviews.operation.datashader import datashade

hv.extension('bokeh')

lats = np.random.uniform(51.111, 51.222, 10000)
longs = np.random.uniform(1.31, 1.33, 10000)

df = pd.DataFrame({"latitude": lats, "longitude": longs})

points = hv.Points(df, ['longitude', 'latitude'])
shader = datashade(points)

EsriImagery * shader

Incorrect axis

However, both of the individual plots are correct:

shader + EsriImagery

enter image description here


Solution

  • HoloViews elements do no know anything about the coordinate system of your data, while tile sources are defined in a Mercator coordinate system. Therefore when you overlay hv.Points on top of a tile source it assumes your coordinates are already in Mercator coordinates. In order to overlay data situated in different coordinates systems you should therefore use the GeoViews elements, e.g. in your case gv.Points, as described in this user guide. This will ensure that your points are interpreted correctly as lat/lon pairs and can be automatically projected into the same coordinate system as the tile source.