【问题标题】:setting cartopy set_extent for pacific ocean (160E ~ -90W or 160 ~ 270) not working为太平洋(160E ~ -90W 或 160 ~ 270)设置 cartopy set_extent 不起作用
【发布时间】:2021-12-22 01:47:16
【问题描述】:

我正在尝试仅在热带太平洋地区投影地图,范围从 160E 到 -90W(或 160 到 270),如下例所示

paco_region    =  plt.axes(projection=ccrs.PlateCarree())
paco_region.coastlines()
paco_region.set_extent([160,-90,-20,20],crs=ccrs.PlateCarree())
paco_region.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)

plt.show()

问题是 cartopy 拒绝显示从 160E(设置为左边界)到 -90W(设置为右边界)的地图。它只是显示从-90W到160W的地图(如下图)

我该如何解决这个问题?

【问题讨论】:

    标签: cartopy


    【解决方案1】:

    你需要一些坐标变换和一些小技巧来完成它。

    import matplotlib.pyplot as plt
    import cartopy.crs as ccrs
    
    # define CRS's for our use case
    crs0 = ccrs.PlateCarree(central_longitude=0)     #for coding data, same as ccrs.PlateCarree()
    crs180 = ccrs.PlateCarree(central_longitude=180) #for plotting map in pacific area
    
    # For all plotting, use `crs180`
    fig, paco_region = plt.subplots(figsize=(9,5), subplot_kw={'projection': crs180})
    
    #paco_region.stock_img()  # background image check-plot
    paco_region.coastlines()
    
    paco_region.set_extent([160, 270, -20, 20], crs=crs0)
    
    # Sample plot of users' data
    # Just use regular long/lat
    lons = [175, 185, 195, 220, 250]
    lats = [15, 0, -15, 12, 18]
    # ... but specify `transform = crs0` when plot the data.
    paco_region.scatter(lons, lats, transform=crs0, color="r")
    
    # For grid-line labelling, use `crs0`
    paco_region.gridlines(crs=crs0, draw_labels=True)
    
    plt.show()
    

    【讨论】:

    • 感谢您的解决方案。但是有没有办法在不使用plt.subplot 的情况下实现这一点?我问这个是因为我不知道如何实际制作子图。
    • @Redshoe 试试help(plt.subplots) 看看如何使用subplots。您可以指定 ncols、nrows 等来获得所需的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2017-09-14
    • 2015-01-22
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    相关资源
    最近更新 更多