【发布时间】:2026-01-06 13:55:02
【问题描述】:
我正在尝试增加 Python 中 NorthPolarStereo 投影上经线出现的间隔。我尝试增加/定义刻度/lim(对于 x 和 y 坐标)并返回错误“具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()” .我也尝试过改变范围的界限。我发现一篇文章提到了使用底图,但我认为我不需要整体使用它。我用于投影的基本代码的链接是here。 代码片段在这里:
# Generate axes, using Cartopy, drawing coastlines, and adding features
fig=plt.figure(figsize=(10,10))
projection = ccrs.NorthPolarStereo()
ax = plt.axes(projection=projection)
ax.coastlines(linewidths=0.5)
ax.add_feature(cfeature.LAND, facecolor='lightgray')
ax.set_extent([-180,180,90,0],ccrs.PlateCarree())
gl = ax.gridlines(crs=ccrs.PlateCarree(),linestyle="--", linewidth=1, color='k', alpha=0.5)
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_xticks([180,150,120,90,60,30])
ax.set_boundary(circle, transform=ax.transAxes)
p=wrap_U.plot.contour(ax=ax,vmin=-8,vmax=16, transform=ccrs.PlateCarree(),
levels = 7, linewidths=0.5, cmap='k')
ax.clabel(p, np.arange(-8,16,8),fmt='%d', inline=1, fontsize=14)
gvutil.set_titles_and_labels(ax,
lefttitle="Zonal Wind", righttitle="m/s")
#This line leads to truth value error
gvutil.set_axes_limits_and_ticks(ax, xticks=np.linspace(-180, 180), xticklabels=['180S', '90S', '0', '90N', '180N'],
ylim=ax.get_ylim()[::-1], yticks=U)
# Show the plot
plt.show()
我确实设置了一个自定义 anaconda 环境,所以如果需要更多信息,我也可以链接到哪里可以找到该环境。
【问题讨论】:
-
你检查我的答案了吗?尝试运行我的代码并给我反馈。
标签: python dictionary projection cartopy