【发布时间】:2020-08-28 09:51:41
【问题描述】:
我正在尝试使用以下内容创建一个 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()
出现的问题是子图中的底图范围仅限于叠加点数据。如何更改它,以便每个子图都有一个覆盖整个子图的底图。
【问题讨论】:
-
首先设置斧头限制(使用 set_aspect)可能会有所帮助,然后才调用
add_basemap(因为这只会在被调用时获取ax的当前范围所需的那些图块) -
我已经尝试在设置方面后订购 add_basemap 并且它不会改变问题。
-
你能提供一个可重现的例子吗? (例如,如果您无法共享数据,则使用一些半随机点)
标签: python geopandas contextily