在 x 和 y 轴上显示纬度和经度值

Display latitude and longitude values on x and y axis

如何在图表的 x 轴和 y 轴上添加纬度和经度值?

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


def main():
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([-20, 60, -40, 45], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)

    plt.show()

main()

要在坐标轴上绘制网格和标签,需要添加此命令(在ax.add_feature之后):

ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)

情节应该是这样的:

编辑

要对 gridliners 的组件进行更多控制,请按以下代码所示离散地设置它们的值 [True / False]:

gridliner = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)
gridliner.xlabels_top = True
gridliner.xlabels_bottom = True
gridliner.ylabels_left = True
gridliner.ylabels_right = True
gridliner.ylines = True  # you need False
gridliner.xlines = True  # you need False