简体   繁体   中英

Display latitude and longitude values on x and y axis

How can I add the latitude and longitude values on the x and y axis of my graph?

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()

To draw grid and labels on the axes, you need to add this command (after ax.add_feature ):

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

and the plot should look like this:

在此处输入图片说明

Edit

To enable more control on the components of the gridliners , set the the values [True / False] on them discretely as shown in the code below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM