【问题标题】:Share x and y axis between subplots with map与地图共享子图之间的 x 和 y 轴
【发布时间】:2019-05-01 00:08:15
【问题描述】:

我想使用sharexsharey 在两个子图中同步zoomingclicking

这是一个简单的代码:

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轴实际上理解sharexsharey;如果他们这样做可能是巧合。
  • @ImportanceOfBeingErnest 我认为它确实有效。刚开始就有问题。搬家后还是一样。您可以查看更新。
  • 实际上我在运行代码时无法重现该问题。对我来说,这些情节从一开始就是同步的。
  • @ImportanceOfBeingErnest 我添加另一个示例。你能检查一下吗? cartopy的版本是0.17.0。
  • This is the output 我的新代码。我正在使用 cartopy 0.16.0。

标签: python matplotlib matplotlib-basemap cartopy


【解决方案1】:

matplotlib的版本有关。 更新到3.0.2后,现在可以正常使用了。

【讨论】:

    猜你喜欢
    • 2019-09-03
    • 1970-01-01
    • 2021-05-12
    • 2014-09-07
    • 2012-10-06
    • 2021-03-14
    • 2021-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多