我仍然对Cartopy的某些方面感到困惑。我不明白为什么有些指令不起作用...例如,如果我想绘制一张英国地图,则可以使用下面的程序,然后得到地图。
[我了解Orthographic
投影使用度表示经度和纬度,因此我将extent = [-6.5, 3.5, 49.5, 59.0]
设置为限制地图,其中-6.5
表示东经的6.5°
,3.5
表示西经的3.5°
等等
为此,如果我想在地图上突出显示格林威治,我认为我必须先定义其坐标:Greenwich_lon, Greenwich_lat = 0.0, 51.0
,然后绘制这些坐标:ax.plot(Greenwich_lon, Greenwich_lat, marker='x', markersize=12, color='red')
。
但是这在地图上给了我一个完全outside正确的地方!
为什么会这样?它是否来自ax.plot
,不合适吗?它是否来自Greenwich_lon
中参数Greenwich_lat
和ax.plot
的定位(我颠倒了它们,但没有改变)?它是否来自ax.plot
中缺少的某些指令?它来自使用的投影系统吗?
我在哪里可以找到通过示例简单表达的解释?我知道Cartopy有大量的文档here,但它是如此庞大,我比其他任何人都失去了更多...
import matplotlib.pyplot as plt
import cartopy
import cartopy.feature as cf
import cartopy.crs as ccrs
import numpy as np
plt.figure(figsize=(8, 8))
extent = [-6.5, 3.5, 49.5, 59.0]
central_lon = np.mean(extent[:2])
central_lat = np.mean(extent[2:])
proj = ccrs.Orthographic(central_lon, central_lat)
ax = plt.axes(projection=proj)
ax.set_extent(extent)
ax.gridlines()
border = cf.NaturalEarthFeature(
'cultural', 'admin_0_boundary_lines_land', scale='110m')
land = cf.NaturalEarthFeature(
'physical', 'land', scale='110m',
edgecolor='black', facecolor=cfeature.COLORS['land'])
ocean = cf.NaturalEarthFeature(
'physical', 'ocean', scale='110m',
edgecolor='none', facecolor=cfeature.COLORS['water'])
ax.add_feature(border)
ax.add_feature(land)
ax.add_feature(ocean)
Greenwich_lon, Greenwich_lat = 0.0, 51.0
ax.plot(Greenwich_lon, Greenwich_lat, marker='x', markersize=12, color='red')
plt.show()
projection
坐标进行绘制(与Matplotlib中的data
坐标相同)。通常,它在大多数投影坐标系中接受带有指定数据坐标系的选项的输入数据。您有责任在附带选项的情况下使用正确的值。例如,如果XXXX()是您的数据基于的地图投影坐标,则>>
.set_extent(lon_min, lon_max, lat_min, lat_max, crs=cartopy.crs.XXXX())
.plot(lon, lat, marker'x', transform=cartopy.crs.XXXX())
如果使用纬度/经度,则可以使用PlateCarree()代替上面的XXXX()。但是,出于方便起见,.set_extent()将crs = cartopy.crs.PlateCarree()作为您通常忽略的默认选项。
有关坐标系和变换的更多信息:
Cartopyhttps://scitools.org.uk/cartopy/docs/latest/tutorials/understanding_transform.html由于Cartopy是基于Matplotlib构建的,因此您需要研究Matplotlib中的相关主题。
Matplotlibhttps://matplotlib.org/3.2.1/tutorials/advanced/transforms_tutorial.html