当设置set_aspect('equal', adjustable='datalim')
我的情节的实际范围时,我的情节得到了调整,并且比我最初设置的范围略宽 - 这是预期的。
然而,当我试图获得这些调整后的边界时,get_extent()
只返回我输入的内容set_extent()
。
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cpf
import shapely.geometry as sgeom
EXT = (9000000, 13500000, -450000, 3500000)
def to_bounds(extent):
xmin, a, b, ymax = extent
return xmin, b, a, ymax
platecarree = ccrs.PlateCarree(globe=ccrs.Globe(datum='WGS84', ellipse='WGS84'))
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(1, 1, 1, projection=platecarree)
ax.set_extent(EXT, crs=platecarree) # setting extent
ax.set_aspect('equal', adjustable='datalim', anchor='C')
ext2 = ax.get_extent() # trying to get the updated extent
ax.add_feature(cpf.LAND, facecolor='#bababa')
ax.add_feature(cpf.BORDERS, edgecolor='white')
ax.add_geometries([sgeom.box(*to_bounds(EXT))], crs=platecarree, facecolor='none', edgecolor='yellow', linewidth=3) # initial extent
ax.add_geometries([sgeom.box(*to_bounds(ext2))], crs=platecarree, facecolor='none', edgecolor='indianred', linewidth=1) # updated extent
Obvioulsy,EXT和ext2是一样的。
最奇怪的是,在我运行上面的代码之后,get_extent()
实际上会给我更新的值。
ext2 # (9000000.0, 13499999.999999998, -449999.99999999994, 3500000.0)
ax.get_extent() # (8546909.492273731, 13953090.507726269, -449999.99999999994, 3500000.0)
怎么了 ?