我正在尝试将底图添加到我存储在名为 top_data 的 pandas 数据框中的一些地理空间数据(其中每个点的经度为“long”列,纬度为“lat”)。这是我正在运行的代码:
import pandas as pd
import contextily
import geoplot as gplt
import geoplot.crs as gcrs
import geopandas as gpd
from shapely.geometry import Point
crs={'init':'epsg:4327'}
geom = [Point(xy) for xy in zip(top_data['long'],top_data['lat'])]
gdf = gpd.GeoDataFrame(top_data, crs=crs,geometry=geom)
gdf=gdf.to_crs(epsg=3857) #redundant but just to be sure
ax=gplt.kdeplot(data=gdf[:k],x='long',y='lat',shade=True,bw_method=bw,n_levels=50,alpha=0.55,cmap='viridis')
contextily.add_basemap(ax)
初始 KDE 绘图工作正常,但添加底图会产生: UserWarning:推断的缩放级别 29 对当前切片提供程序无效(有效缩放:0 - 18)。警告。警告(味精)
和一个空白的情节我也尝试在 add_basemap 函数中设置 crs 并得到同样的错误。以下是 geopandas df 的前几行:
long lat geometry
3 -84.38473 33.67726 POINT (-9393665.174 3985547.819)
4 -84.38978 33.75432 POINT (-9394227.338 3995860.718)
5 -84.36122 33.81038 POINT (-9391048.053 4003369.023)
6 -84.49328 33.68845 POINT (-9405748.905 3987044.797)
7 -84.36454 33.87531 POINT (-9391417.634 4012071.469)