cartopy 设置范围,central_longitude=180

And*_*rew 5 python dictionary matplotlib cartopy extent

Cartopy 0.17.0:当我设置central_longitude时,我不知道如何准确设置提供的范围:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

projection = ccrs.PlateCarree(central_longitude=180)
ax = plt.axes(projection=projection)
ax.coastlines()
ax.set_extent((-120, 120, -45, 45), crs=ccrs.PlateCarree())
ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree())
Run Code Online (Sandbox Code Playgroud)

这正确地划分了纬度子集: y_正确 这正确地划分了经度子集,但有额外的标签:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

projection = ccrs.PlateCarree(central_longitude=180)
ax = plt.axes(projection=projection)
ax.coastlines()
ax.set_extent((-120, 120, -45, 45))
ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述 这可以正确设置纬度:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

projection = ccrs.PlateCarree(central_longitude=180)
ax = plt.axes(projection=projection)
ax.coastlines()
ax.set_extent((-120, 120, -45, 45), crs=projection)
ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree())
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

swa*_*hai 8

使用 Cartopy 绘制世界日期变更线的地图并不像您发现的那么简单。它需要一些技巧才能做到正确。最重要的是必须在代码的所有部分正确使用 CRS。

代码:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# cartopy-0.17.0 pyshp-2.1.0

cm = 180
proj = ccrs.PlateCarree(central_longitude=cm)
fig = plt.figure(figsize=[5, 8])
ax = fig.add_subplot(1, 1, 1, projection=proj)
ax.coastlines()

# original ax.set_extent((-120, 120, -45, 45)) ?
# Need longitude extent from -60 to +60 on PlateCarree(central_longitude=180)
minlon = -60 + cm
maxlon = +60 + cm
ax.set_extent([minlon, maxlon, -45, 45], ccrs.PlateCarree())
ax.gridlines(draw_labels=True, crs=proj)
plt.show()
Run Code Online (Sandbox Code Playgroud)

输出plot1,经度标签在PlateCarree(central_longitude=180)中,这本身是自然的,但不是地理标准。

在此输入图像描述

如果您想在上图中使用普通的地理经度标签,则不能简单地使用

ax.gridlines(draw_labels=True, crs=PlateCarree())
Run Code Online (Sandbox Code Playgroud)

正如您所发现的,在代码中。

输出plot2,带有普通地理经度标签

这需要 ax.gridlines() 中的具体指令如下:

ax.gridlines(draw_labels=False, crs=ccrs.PlateCarree(), xlocs=[120,140,160,180,200,220,240])
ax.gridlines(draw_labels=True, crs=ccrs.PlateCarree(), xlocs=[120,140,160,180,-160,-140,-120])
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

希望这对所有读者有用。


小智 0

它取决于“class PlateCarree”属性(以及所使用的 CylindricalProjection 的属性)。请参阅文档。经度值 180 是边界。

如果设置范围 [120 180 ...] 或 [-120 180 ...] 则没有问题。

ax.set_extent([-120, 180, -45, 45]) ax.set_extent([120, 180, -45, 45])

我认为尝试其他投影是有意义的。