你如何裁剪网格线,使它们不会出现在带有 cartopy 的大陆上?
How do you clip gridlines so that they don't appear over continents with cartopy?
我想使用 cartopy 创建一张地图,绘制被大陆剪裁的网格线,以便它们只出现在海洋上而不是陆地上。它们是否真的被剪裁了,或者我是否只是控制绘图顺序以便我的数据被绘制在它们上面对我来说并不重要;两种方法都行。
我在 Python 3,使用 cartopy 0.17 和 matplotlib 3.1.1。
from cartopy.crs import PlateCarree
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1), projection=PlateCarree())
ax.gridlines()
ax.coastlines()
我之前试过调用 gridlines
和 coastlines
,反之亦然,但无论哪种方式,网格线最终都会在大陆上绘制,所以很明显,这些东西的绘制顺序是确定的以不同的方式。
我也试过使用 ax.contourf
绘制一些数据,我得到了同样的结果:网格线出现在数据创建的不透明颜色之上。所以不只是coastlines
只画了个轮廓而已。
这是你想要的结果吗?
from cartopy.crs import PlateCarree
import cartopy
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1), projection=PlateCarree())
ax.add_feature(cartopy.feature.LAND, facecolor='white', zorder=1)
ax.add_feature(cartopy.feature.COASTLINE)
ax.gridlines(zorder=0)
我想使用 cartopy 创建一张地图,绘制被大陆剪裁的网格线,以便它们只出现在海洋上而不是陆地上。它们是否真的被剪裁了,或者我是否只是控制绘图顺序以便我的数据被绘制在它们上面对我来说并不重要;两种方法都行。
我在 Python 3,使用 cartopy 0.17 和 matplotlib 3.1.1。
from cartopy.crs import PlateCarree
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1), projection=PlateCarree())
ax.gridlines()
ax.coastlines()
我之前试过调用 gridlines
和 coastlines
,反之亦然,但无论哪种方式,网格线最终都会在大陆上绘制,所以很明显,这些东西的绘制顺序是确定的以不同的方式。
我也试过使用 ax.contourf
绘制一些数据,我得到了同样的结果:网格线出现在数据创建的不透明颜色之上。所以不只是coastlines
只画了个轮廓而已。
这是你想要的结果吗?
from cartopy.crs import PlateCarree
import cartopy
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes((0, 0, 1, 1), projection=PlateCarree())
ax.add_feature(cartopy.feature.LAND, facecolor='white', zorder=1)
ax.add_feature(cartopy.feature.COASTLINE)
ax.gridlines(zorder=0)