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