用正投影错误地绘制卡通点

2024-04-18 09:38:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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()

Plot output

测试方法:

cartopy==0.16.0和{}

proj4==4.9.3proj4==5.0.1proj4==5.0.2

我唯一的提示是使用Cartopy-0.16.1.dev179-proj4==5.0.1,我得到了这个UserWarning

^{pr2}$

我在https://github.com/SciTools/cartopy/issues/1172上打开了一期,但该期已关闭。有人知道如何让卡通片正确地工作与正交投影?在


Tags: importforplotastransformpltaxcentral
1条回答
网友
1楼 · 发布于 2024-04-18 09:38:09

据我所知,有几种方法可以用来获得预期的结果。在

首先,显式地变换本投影中的点。。。在

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点转换为本地正交点可以避免此问题。在

了解了这些信息,我们可以选择调用适当的方法,将点列表视为单个点(并避免cartopy做出不符合我们期望的假设),方法是使用scatter,而不是{}。。。在

^{pr2}$

这对我也有用。在

高温

相关问题 更多 >