When dataset has only one point, map is not showing

Hi all,
I’m new to visualizing spatial data. When I try to plot one point with the map in the background, the map is not showing. But if I add a second point to the dataset, it’s showing as desired.
I’ve made a minimum example code with two coords dataset, one with one point and the other one with two.

one point:

two points:

Here’s the code:

!python --version
!pip list|grep -E 'panel|holoviews|geoviews|pandas'

import panel as pn
import holoviews as hv
import geoviews as gv
from geoviews import opts, tile_sources as gvtsa
hv.extension('bokeh')
import pandas as pd
# import datashader as ds

tile_map = gv.tile_sources.OSM.opts(
                global_extent=False,
                width=500,
                height=475)

# coords={'longitude_': [-122.3328], 'latitude_': [47.6061], 'city': ['Seattle']}
coords={'longitude_': [-122.3328, -122.6784], 'latitude_': [47.6061, 45.5152], 'city': ['Seattle', 'Portland']}
df = pd.DataFrame(coords)
df["x"], df["y"] = ds.utils.lnglat_to_meters(df.longitude_, df.latitude_)
points = hv.Points(df,kdims=["x", "y"],vdims=['city']).opts(color="black", size=10, tools=['hover'])

geo_opts = dict(
                logz=True,
                colorbar=True,
                xlabel="Longitude",
                ylabel="Latitude"
            )

points.opts(**geo_opts) * tile_map

Any tip on how gv.tile_sources.OSM works is appreciated.

I added the following argument to the geo_opts, now it zooms to the single point in the plot but still map in the background is not showing.

default_span=2.0

Hi Mana, I believe you should try using gv.Points instead of hv.Points

Or, alternatively, try out hvplot:
df.hvplot("longitude_", "latitude_", tiles=True, geo=True)
https://hvplot.holoviz.org/reference/geopandas/points.html

Hi @ahuang11
Thanks for your tips.
I tried gv.Points instead of hv.Points. Now, it doesn’t show map in either case (one point or more) with the following warning that I’m not sure how to resolve.

WARNING:param.project_points: While projecting a Points element from a PlateCarree coordinate reference system (crs) to a Mercator projection none of the projected paths were contained within the bounds specified by the projection. Ensure you have specified the correct coordinate system for your data.

I think you need to specify a projection=ccrs.GOOGLE_MERCATOR.

See right above Working with Bokeh — GeoViews v1.10.1 for example.

I specified projection, no luck yet.

I also tried hvplot, same result.

I think you might be pre-projecting the coords; you can drop that and just specify projection like this

import panel as pn
import holoviews as hv
import geoviews as gv
from geoviews import opts, tile_sources as gvtsa

hv.extension("bokeh")
import pandas as pd
import cartopy.crs as ccrs

tile_map = gv.tile_sources.OSM.opts(global_extent=False, width=500, height=475)

coords = {
    "lon": [-122.3328, -122.6784],
    "lat": [47.6061, 45.5152],
    "city": ["Seattle", "Portland"],
}
df = pd.DataFrame(coords)
points = gv.Points(df, kdims=["lon", "lat"], vdims=["city"]).opts(
    color="black", size=10, tools=["hover"], projection=ccrs.GOOGLE_MERCATOR
)

geo_opts = dict(logz=True, colorbar=True, xlabel="Longitude", ylabel="Latitude")
points.opts(**geo_opts) * tile_map

Thank you so much for your help.
Again, it’s working when dataset has more than one data points.
In your code, when I eliminated Portland from the dataset which means that we left only with one data point in the dataset, then the map didn’t show in the background, neither it zoomed to the point.
I’m wondering if this is an edge case, or it needs some more settings.
The default_span=2.0 should do it, but even adding that didn’t solve the problem.

coords = {
“lon”: [-122.3328],
“lat”: [47.6061],
“city”: [“Seattle”],
}

I got it! Here’s how default_span works:

(points.opts(**geo_opts) * tile_map).opts(default_span=2.0,)
1 Like