[GIS] Contextily not showing basemap

basemapgeopandaspython

I have a geopandas dataframe that contains bus boarding data. I'm trying to display a subset of the data on a plot using a Contextily basemap but the basemap does not appear.

I created the geometry attribute this way.

geometry = [Point(xy) for xy in zip(df['longitude'], df['latitude'])]
crs = {'init':'epsg:3857'}

gdf = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)

My data looks like this.

stop name   |   latitude    |   longitude   |  geometry
----------------------------------------------------------------------
stop a      |  36.09541     |  -79.5464     | POINT(-79.5464,36.09541)
unknown     |  0.0000       |  0.00000      | POINT(0.0000,0.0000)
unknown     |  36.14894     |  -80.5465     | POINT(-80.5465,36.14894)

Some of the data has unknown stop names and I'm trying to plot those that have a lat/long. It is possible that some data do not have coordinate locations.

unknown_transfer_loc = transfer_stops[(transfer_stops['stopName'] == 'unknown') & (transfer_stops['latitude'] != 0)]

ax = unknown_transfer_loc.plot(figsize=(12,7))
cx.add_basemap(ax, zoom=10, source=cx.providers.CartoDB.Voyager)

Using the code above, I can successfully plot the points but the basemap is blank, see image. How can I get the basemap to appear?

enter image description here

Best Answer

After chatting with folks on the Spatial Community slack channel, we were able to generate a nice plot. I had to set the crs parameter in the .add_basemap() function.

ax = unknown_transfer_loc.plot(figsize=(12,7))
cx.add_basemap(ax, zoom=15, crs='EPSG:4326', source=cx.providers.CartoDB.Voyager)

enter image description here