简体   繁体   English

Cartopy 极坐标立体图中轮廓的奇怪行为

[英]Strange behavior with contours in Cartopy polar stereographic plot

I'm trying to create a contour plot on a North Polar Stereographic map projection using Cartopy.我正在尝试使用 Cartopy 在北极立体地图投影上创建等高线图。 I used add_cyclic_point() to try and get around the problem of having a gap between longitude 0 and longitude 35X and followed an example from the documentation ( always_circular_stereographic ) to set up the map axes.我使用add_cyclic_point()来尝试解决经度 0 和经度 35X 之间存在差距的问题,并按照文档( always_circular_stereographic )中的示例设置地图轴。

When I call plt.contour , I get the following plot.当我调用plt.contour ,我得到以下图。 It looks like the contour plotter is getting confused at the transition from 355 to 0 longitude, and sends contour lines around the globe.看起来等高线绘图仪在从 355 经度到 0 经度的过渡中感到困惑,并在全球范围内发送等高线。

在此处输入图片说明

Here is my code:这是我的代码:

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()

How do I do a Cartopy contour plot properly?如何正确绘制 Cartopy 等高线图? Also, why do the contours only show up with transform=ccrs.PlateCarree() and not with transform=ccrs.NorthPolarStereo() ?另外,为什么轮廓只出现在transform=ccrs.PlateCarree()而不是transform=ccrs.NorthPolarStereo()

Apparently the add_cyclic_point function is just for the data;显然add_cyclic_point函数只是为了数据; the contour routine treats 0 different than 360. So the simple fix is to set轮廓例程处理 0 与 360 不同。所以简单的解决方法是设置

lons = np.arange(0,360,5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM