Python 使用正交投影的Cartopy打印点不正确
我正在尝试使用Cartopy和Anaconda Python绘制地图点,但在转换过程中遇到了一些奇怪的失败。在我的简单示例中,我试图绘制3个点,但它们会加倍Python 使用正交投影的Cartopy打印点不正确,python,cartopy,Python,Cartopy,我正在尝试使用Cartopy和Anaconda Python绘制地图点,但在转换过程中遇到了一些奇怪的失败。在我的简单示例中,我试图绘制3个点,但它们会加倍 import matplotlib.pyplot as plt import cartopy.crs as ccrs lons = [214.5, 2.7, 197.5]
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
lons = [214.5, 2.7, 197.5]
lats = [35, 36, 37.]
ax = plt.axes(projection=ccrs.Orthographic(
central_longitude=0,
central_latitude=90))
# plot lat/lon points
ax.plot(lons, lats, 'ro',
transform=ccrs.Geodetic())
# plot north pole for reference
ax.plot([0], [90], 'b^',
transform=ccrs.Geodetic())
# add coastlines for reference
ax.coastlines(resolution='50m')
ax.set_global()
plt.show()
通过以下方式进行测试:
cartopy==0.16.0
和cartopy-0.16.1.dev179-
proj4==4.9.3
,proj4==5.0.1
,proj4==5.0.2
我唯一的提示是,使用Cartopy-0.16.1.dev179-
和proj4==5.0.1
,我得到了这个UserWarning
:
/Users/***/anaconda3/lib/python3.6/site-packages/cartopy/crs.py:1476: UserWarning: The Orthographic projection in Proj between 5.0.0 and 5.1.0 incorrectly transforms points. Use this projection with caution.
我在上打开了一个问题,但该问题已关闭。有人知道如何让cartopy正确使用正交投影吗?据我所知,有几种方法可用于获得预期的结果 首先,显式变换本机投影中的点
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# create the lat/lon points
lons = np.array([214.5, 2.7, 197.5])
lats = np.array([35, 36, 37.])
# create the projections
ortho = ccrs.Orthographic(central_longitude=0, central_latitude=90)
geo = ccrs.Geodetic()
# create the geoaxes for an orthographic projection
ax = plt.axes(projection=ortho)
# transform lat/lons points to othographic points
points = ortho.transform_points(geo, lons, lats)
# plot native orthographic points
ax.plot(points[:, 0], points[:, 1], 'ro')
# plot north pole for reference (with a projection transform)
ax.plot([0], [90], 'b^', transform=geo)
# add coastlines for reference
ax.coastlines(resolution='50m')
ax.set_global()
这就像预期的那样
您看到的原始问题是,cartopy
试图将点序列解释为有界几何体(或路径),但有点困惑。将lat/lon点显式转换为本机正交点可以避开此项目符号
了解这些信息后,我们可以通过使用scatter
而不是plot
调用适当的方法,将点列表视为单个点(并避免cartopy
做出不符合我们期望的假设)
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# create the lat/lon points
lons = np.array([214.5, 2.7, 197.5])
lats = np.array([35, 36, 37.])
# create the projections
ortho = ccrs.Orthographic(central_longitude=0, central_latitude=90)
geo = ccrs.Geodetic()
# create the geoaxes for an orthographic projection
ax = plt.axes(projection=ortho)
# plot native orthographic scatter points
ax.scatter(lons, lats, marker='o', c='r', transform=geo)
# plot north pole for reference
ax.plot([0], [90], 'b^', transform=geo)
# add coastlines for reference
ax.coastlines(resolution='50m')
ax.set_global()
这也适用于我
由于以下原因,HTH也应固定在v0.17中