Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用正交投影的Cartopy打印点不正确_Python_Cartopy - Fatal编程技术网

Python 使用正交投影的Cartopy打印点不正确

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]

我正在尝试使用Cartopy和Anaconda Python绘制地图点,但在转换过程中遇到了一些奇怪的失败。在我的简单示例中,我试图绘制3个点,但它们会加倍

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中