Cartopy 绘图点与正交投影不正确
Cartopy plotting points incorrectly with Orthographic projection
我正在尝试使用 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.
我在 https://github.com/SciTools/cartopy/issues/1172 上打开了一个问题,但该问题已关闭。有人知道如何让 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()
这个情节符合预期...
Expected Orthographic projection plot
您看到的最初问题是 cartopy
试图将点序列解释为有界几何(或路径),但有点混乱。将 lat/lon 点显式转换为原生正交点可避免此子弹。
了解这些信息后,我们可以通过使用 scatter
而不是 plot
...
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
我正在尝试使用 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.
我在 https://github.com/SciTools/cartopy/issues/1172 上打开了一个问题,但该问题已关闭。有人知道如何让 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()
这个情节符合预期...
Expected Orthographic projection plot
您看到的最初问题是 cartopy
试图将点序列解释为有界几何(或路径),但有点混乱。将 lat/lon 点显式转换为原生正交点可避免此子弹。
了解这些信息后,我们可以通过使用 scatter
而不是 plot
...
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