【发布时间】:2019-05-01 00:08:15
【问题描述】:
我想使用sharex 和sharey 在两个子图中同步zooming 和clicking。
这是一个简单的代码:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
proj = ccrs.LambertConformal(central_latitude=39,central_longitude=-95,
standard_parallels = (39, 39))
fig = plt.figure(figsize=(12,12))
ax1 = plt.subplot(2,2,1,projection = proj)
ax2 = plt.subplot(2,2,2,projection = proj,sharex=ax1, sharey=ax1)
ax1.coastlines()
ax2.coastlines()
ax1.add_feature(cfeature.STATES)
ax2.add_feature(cfeature.STATES)
ax1.set_extent([-100, -80, 20, 35], crs=ccrs.PlateCarree())
ax2.set_extent([-100, -80, 20, 35], crs=ccrs.PlateCarree())
lon, lat = -85, 25
ax1.scatter(lon,lat,transform=ccrs.PlateCarree())
ax2.scatter(lon,lat,transform=ccrs.PlateCarree())
plt.show()
但是,地图的范围不同:
用moving工具稍微移动一下,还是一样的!
这是另一个例子:
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
proj = ccrs.PlateCarree()
ax1 = plt.subplot(1,4,1,projection = proj)
ax2 = plt.subplot(1,4,2,projection = proj,sharex=ax1, sharey=ax1)
ax3 = plt.subplot(1,4,3,projection = proj,sharex=ax1, sharey=ax1)
ax4 = plt.subplot(1,4,4,projection = proj,sharex=ax1, sharey=ax1)
for ax in [ax1,ax2,ax3,ax4]:
ax.coastlines()
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, color='gray', alpha=0.5, linestyle='--')
ax.set_extent([-105, -75, 25, 50], crs=ccrs.PlateCarree())
plt.show()
而且,结果看起来很奇怪:
【问题讨论】:
-
哦,我不认为cartopy轴实际上理解
sharex和sharey;如果他们这样做可能是巧合。 -
@ImportanceOfBeingErnest 我认为它确实有效。刚开始就有问题。搬家后还是一样。您可以查看更新。
-
实际上我在运行代码时无法重现该问题。对我来说,这些情节从一开始就是同步的。
-
@ImportanceOfBeingErnest 我添加另一个示例。你能检查一下吗? cartopy的版本是0.17.0。
-
This is the output 我的新代码。我正在使用 cartopy 0.16.0。
标签: python matplotlib matplotlib-basemap cartopy