如何将真实地图添加为绘图的背景

How to add a real map as the background to a plot

我正在尝试在我的地块后面添加一张真实地图,以显示我的数据点的位置。

但是不知道怎么添加实景图...

我尝试了几种方法,比如在情节后面放另一个 png。

但这就是不对。

这是我得到的。

import geopandas as gpd
import tilemapbase

BBox = (df.Longitude.min(), df.Longitude.max(), df.Latitude.min(), df.Latitude.max())
print(BBox)
(3.3990449, 7.042425700000001, 50.8134557, 53.4066264)

tilemapbase.start_logging()
tilemapbase.init(create=True)
extent = tilemapbase.extent_from_frame(NL_shape, buffer = 25)

fig, ax = plt.subplots(figsize=(10,10))
plotter = tilemapbase.Plotter(extent, tilemapbase.tiles.build_OSM(), width=1000)
plotter.plot(ax)
ax.set_xlim(BBox[0]-0.2, BBox[1]+0.2)
ax.set_ylim(BBox[2]-0.5, BBox[3]+0.5)
NL_shape.plot(ax=ax, alpha=0.3, edgecolor="black", facecolor="white")
stores_shape.plot(ax=ax, alpha = 0.2, color="red", marker='o');

我按照这里的说明操作:https://rosenfelder.ai/create-maps-with-python/

我用 geopandas 读取国家边界(json)然后绘制我的数据。

但是我不能使用tilemapbase下载realmap

结果是这样的:

有谁知道如何解决这个问题?谢谢。

期待的画面是这样的。底图应该喜欢 OpenStreetmap。

我使用CONTEXTILY后出现错误

显示如下:

使用 contextily 为 GeoPandas 制作的库。 - https://contextily.readthedocs.io/en/latest/

import contextily as cx

fig, ax = plt.subplots(figsize=(10,10))
NL_shape.plot(ax=ax, alpha=0.3, edgecolor="black", facecolor="white")
stores_shape.plot(ax=ax, alpha = 0.2, color="red", marker='o');
cx.add_basemap(ax, crs=NL_shape.crs, source=cx.providers.OpenStreetMap.Mapnik)