我正在尝试使用以下内容创建一个2x2的子图:
import geopandas as gpd
import matplotlib.pyplot as plt
import contextily as ctx
site = gdf.groupby('Site_name')
plt.figure(figsize =(20,20))
# Iterate through sites
for i, (Site_name, site_gdf) in enumerate(site):
# create subplot axes in a 2x2 grid
ax = plt.subplot(2, 2, i + 1) # nrows, ncols, axes position
# plot the site on these axes
site_gdf.plot(ax=ax)
ctx.add_basemap(ax, source=ctx.providers.Esri.WorldImagery)
# set the title
ax.set_title(Site_name)
# set the aspect
# adjustable datalim ensure that the plots have the same axes size
ax.set_aspect('equal', adjustable='datalim')
plt.tight_layout()
plt.show()出现的问题是,子地块中底图的范围仅限于叠加点数据。如何更改它,使每个子图都有一个覆盖整个子图的底图。

发布于 2020-09-16 21:35:50
我的解决方案是,我搜索最外层的点,然后更改matplotlib轴
ax.set_xlim(x_min-addition, x_max+addition)
ax.set_ylim(y_min-addition, y_max+addition)在这种情况下,加法只是一个增加点数视图的数字,如0.001。x_min是最小的点,x_max是最大的点,以此类推。之后,我得到了我的底图。
ctx.add_basemap(ax,...)如果你知道所有点的最外边界,你可以直接传递它们。结果应该是相同大小的。如果你不知道自己的界限,你需要首先找到它们。因此,你可以遍历你的点,然后比较它们(只是一个例子):
for point_data_x, point_data_y in site_data:
if point_data_x < x_min:
x_min = point_data_x
elif point_data_x > x_max:
x_max = point_data_x
if point_data_y < y_min:
y_min = point_data_y
elif point_data_y > y_max:
y_max = point_data_y亲切的问候
https://stackoverflow.com/questions/63631446
复制相似问题