1

I am trying to familiarize myself with creating geographic plots in Python using geopandas and geoplot. So I am working my way through tutorials and documentation.

Currently, I am looking at the user guide for geoplot, but the created plot and the underlying map are misaligned. I am using Windows 10, Python 3.7 (no Anaconda), and am running inside Jupyter.

Here is the code

%matplotlib inline
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs

continental_usa_cities = gpd.read_file(gplt.datasets.get_path('usa_cities'))
continental_usa_cities = continental_usa_cities.query('STATE not in ["AK", "HI", "PR"]')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))

ax = gplt.webmap(contiguous_usa, projection=gcrs.WebMercator())
gplt.pointplot(continental_usa_cities, ax=ax)

I am getting two future warnings and an image that is misaligned (see screenshot below).

Screenshot of Jupyter Notebook showing the missalignment

What am I doing wrong, and what I can look at to debug/correct the alignment?

2
  • Welcome to GIS SE. As a new user, please take the Tour. Error messages should also be posted as text, since they are legible on all display platforms and can be indexed and found by others with a similar problem.
    – Vince
    May 15 '20 at 12:11
  • Thanks for the updated question. This is for sure a bug, and there is not directly something wrong in your code. And this has already been reported, apparently, here: github.com/ResidentMario/geoplot/issues/214
    – joris
    May 17 '20 at 7:55
2

This a bug caused by a mismatch between geoplot and contextily (the package that geoplot uses for adding the web map background), see https://github.com/ResidentMario/geoplot/issues/214. That will certainly be fixed in a future version of geoplot, but for now, you can use contextily directly, by changing this line of your code:

ax = gplt.webmap(contiguous_usa, projection=gcrs.WebMercator())

to

import contextily 
contextily.add_basemap(ax, source=contextily.providers.OpenStreetMap.Mapnik) 

Full working example:

ax = gplt.pointplot(continental_usa_cities, projection=gcrs.WebMercator())

import contextily
contextily.add_basemap(ax, source=contextily.providers.OpenStreetMap.Mapnik)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.