[英]Strange behavior with contours in Cartopy polar stereographic plot
我正在嘗試使用 Cartopy 在北極立體地圖投影上創建等高線圖。 我使用add_cyclic_point()
來嘗試解決經度 0 和經度 35X 之間存在差距的問題,並按照文檔( always_circular_stereographic
)中的示例設置地圖軸。
當我調用plt.contour
,我得到以下圖。 看起來等高線繪圖儀在從 355 經度到 0 經度的過渡中感到困惑,並在全球范圍內發送等高線。
這是我的代碼:
import numpy as np
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point
import matplotlib.pyplot as plt
def define_map():
from matplotlib.path import Path
fig = plt.figure(figsize=(10,10))
ax = plt.axes(projection=ccrs.NorthPolarStereo())
ax.coastlines()
# From example: http://scitools.org.uk/cartopy/docs/latest/examples/always_circular_stereo.html
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 = Path(verts * radius + center)
ax.set_boundary(circle, transform=ax.transAxes)
return(fig, ax)
lats = np.arange(65,91,5)
lons = add_cyclic_point(np.arange(0,359,5))
data = add_cyclic_point(np.random.random((len(lats),len(lons)-1)))
fig, ax = define_map()
plt.contour(lons,lats,data,5,transform=ccrs.PlateCarree(), cmap=plt.cm.Blues)
plt.colorbar(fraction=0.05, shrink=0.9)
plt.show()
如何正確繪制 Cartopy 等高線圖? 另外,為什么輪廓只出現在transform=ccrs.PlateCarree()
而不是transform=ccrs.NorthPolarStereo()
?
顯然add_cyclic_point
函數只是為了數據; 輪廓例程處理 0 與 360 不同。所以簡單的解決方法是設置
lons = np.arange(0,360,5)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.