2
我试图将环形南极立体图的Cartopy example plot改编为北极并向其添加数据。我有几个问题。Cartcopy中pcolormesh的问题
首先,在示例代码中,陆地特征在海洋特征之前被添加。当我这样做时,我得到了一张只有海洋的地图。我在下面的代码中颠倒了电话的顺序,并获得了陆地和海洋的地图。为什么其他订单与南极例子一起工作?
其次,更重要的是,我无法弄清楚为什么我的pcolormesh调用没有任何效果。
我使用Python 2.7.7,matplotlib 1.5.1和Cartopy 0.15.1。
import matplotlib.path as mpath
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs
import cartopy.feature
lats = np.linspace(60,90,30)
lons = np.linspace(0,360,200)
X,Y = np.meshgrid(lons,lats)
Z = np.random.normal(size = X.shape)
def main():
fig = plt.figure(figsize=[10, 5])
ax = plt.subplot(1, 1, 1, projection=ccrs.NorthPolarStereo())
fig.subplots_adjust(bottom=0.05, top=0.95,
left=0.04, right=0.95, wspace=0.02)
# Limit the map to -60 degrees latitude and below.
ax.set_extent([-180, 180, 60, 60], ccrs.PlateCarree())
ax.gridlines()
ax.add_feature(cartopy.feature.OCEAN)
ax.add_feature(cartopy.feature.LAND)
# Compute a circle in axes coordinates, which we can use as a boundary
# for the map. We can pan/zoom as much as we like - the boundary will be
# permanently circular.
theta = np.linspace(0, 2*np.pi, 100)
center, radius = [0.5, 0.5], 0.5
verts = np.vstack([np.sin(theta), np.cos(theta)]).T
circle = mpath.Path(verts * radius + center)
ax.set_boundary(circle, transform=ax.transAxes)
ax.pcolormesh(X,Y,Z,transform=ccrs.PlateCarree())
plt.show()
if __name__ == '__main__':
main()
看起来这是问题,谢谢。我可以问你为什么决定使用不同的纬度/经度网格,为什么你选择层1,3,4而不是0,1,2? –
我专注于绘制特征的顺序。如果我将数据用于'pcolormesh()'图,所有海洋(和格线)将被pcolormesh图层隐藏。对于zorder的值,它们被用来设置绘图的顺序,从而使我们能够生成我们需要的东西。值(1,3,4)可以与(0,1,2)产生不同或相同的输出。请注意,ax.gridlines()也可以具有zorder = some_value,您可以将它带到您可以猜到的值的顶部。要获得更好的地图,还有其他因素需要考虑。 – swatchai