I'm trying to add a contextily basemap to a Matplotlib figure containing a GeoPandas data frame. When I just plot the data frame using
df.plot the map extent is calculated correctly.
However, when I try adding a contextily basemap the map extent (and zoom level) is calculated wrongly and the following warning is shown:
UserWarning: The inferred zoom level of 27 is not valid for the current tile provider (valid zooms: 0 - 20).
I'm trying to execute the following code:
df = gpd.read_file('linz/StatBez_Linz_EPSG_4326.gml') df = df.to_crs(epsg=3857) fig = plt.figure(figsize=(16,9)) ax = plt.subplot() ctx.add_basemap(ax = ax, source=ctx.providers.Stamen.Toner, crs=df.crs.to_string()) df.plot(color='none',edgecolor='green', ax = ax)
The output of
df.tail() can be seen here:
gml file is from data.gv.at