Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion doc/python/scatter-plots-on-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,22 @@ fig.show()
import plotly.express as px
import geopandas as gpd

geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
# Handle both old and new GeoPandas versions without requiring network access
try:
# Try the old method (GeoPandas < 1.0)
geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
except (AttributeError, ValueError):
# Use the new method (GeoPandas >= 1.0)
try:
import geodatasets
geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities'))
Comment on lines +84 to +85
Copy link
Member

@LiamConnors LiamConnors Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This dataset doesn't currently exist on geodatasets, so this will never be successful even with geopandas >=1.0

except ImportError:
# Fallback: build a tiny in-memory GeoDataFrame (no internet or extra deps)
from shapely.geometry import Point
geo_df = gpd.GeoDataFrame(
{"name": ["City A", "City B"], "geometry": [Point(0, 0), Point(10, 10)]},
crs="EPSG:4326",
)

px.set_mapbox_access_token(open(".mapbox_token").read())
fig = px.scatter_geo(geo_df,
Expand Down
17 changes: 16 additions & 1 deletion doc/python/tile-scatter-maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ fig.show()
import plotly.express as px
import geopandas as gpd

geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
# Handle both old and new GeoPandas versions without requiring network access
try:
# Try the old method (GeoPandas < 1.0)
geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
except (AttributeError, ValueError):
# Use the new method (GeoPandas >= 1.0)
try:
import geodatasets
geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities'))
except ImportError:
# Fallback: build a tiny in-memory GeoDataFrame (no internet or extra deps)
from shapely.geometry import Point
geo_df = gpd.GeoDataFrame(
{"name": ["City A", "City B"], "geometry": [Point(0, 0), Point(10, 10)]},
crs="EPSG:4326",
)
Comment on lines +60 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As 'naturalearth.cities' does not exist on geodatasets, I think the best thing to do here would be to have just the example of the dataframe created using GeoDataFrame, like you show in the except block, but with some real cities.

So something like

import plotly.express as px
import geopandas as gpd
from shapely.geometry import Point

geo_df = gpd.GeoDataFrame({
    'name': ['London', 'Paris', 'Berlin', 'Madrid', 'Rome'],
    'geometry': [
        Point(-0.13, 51.51),
        Point(2.35, 48.86),
        Point(13.41, 52.52),
        Point(-3.70, 40.42),
        Point(12.50, 41.90),
    ]
}, crs="EPSG:4326")

fig = px.scatter_map(geo_df,
                    lat=geo_df.geometry.y,
                    lon=geo_df.geometry.x,
                    hover_name="name",
                    zoom=3)
fig.show()

And something similar for the scatter-plots-on-maps example


fig = px.scatter_map(geo_df,
lat=geo_df.geometry.y,
Expand Down