首页 > 解决方案 > 如何在正交图的边界绘制 Lon/Lat 值?

问题描述

我在cartopy中使用了一些南极洲轮廓的shapefile数据,这很好用。我可以用 shapefile 和一些更多的信息生成一个图。但我无法在图像的边界绘制经度和​​纬度信息。

我使用具有central_longitude 和central_latitude 的正交投影。

我还需要提一下,我对 cartopy 比较陌生。

我的代码:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader

# 01

b01e01_lat = -73.86750000
b01e01_lon = -60.22694444
b01e02_lat = -73.89166667
b01e02_lon = -56.68500000
b01e03_lat = -74.87222222
b01e03_lon = -58.26805556
b01e04_lat = -74.85000000
b01e04_lon = -60.43083333
b01e05_lat = -73.86750001
b01e05_lon = -60.22694445

b01_lat = np.array([b01e01_lat,b01e02_lat,b01e03_lat,b01e04_lat, b01e01_lat, b01e05_lat])
b01_lon = np.array([b01e01_lon,b01e02_lon,b01e03_lon,b01e04_lon, b01e01_lon, b01e05_lon])

# 02

b02e01_lat = -73.94555556
b02e01_lon = -51.00055556
b02e02_lat = -74.22333333
b02e02_lon = -49.37000000
b02e03_lat = -74.87555556
b02e03_lon = -50.71888889
b02e04_lat = -74.87583333
b02e04_lon = -51.00055556
b02e05_lat = -73.94555557
b02e05_lon = -51.00055557

fname='Coastline_Antarctica_v02.shp'
#ax = plt.axes(projection=ccrs.SouthPolarStereo())
plt.figure()
ax = plt.axes(projection=ccrs.Orthographic(central_longitude=-41, 
                                              central_latitude=-71))
ax.set_extent([-85,-12,-75,-60], crs=ccrs.PlateCarree())
ax.add_geometries(Reader(fname).geometries(),ccrs.Orthographic(central_longitude=-0, 
                                              central_latitude=-90), color='grey')
ax.gridlines()

plt.plot(b01_lon,b01_lat, color='r', transform=ccrs.PlateCarree())
plt.plot(b02_lon,b02_lat, color='r', transform=ccrs.PlateCarree())

plt.show()

有了这个,我得到以下图(没有蓝色形状): 测试图

任何帮助表示赞赏!

标签: python-3.xcartopy

解决方案


如果您运行代码来生成交互式绘图(%matplotlib notebook在 jupyter notebook 上使用),您可以移动鼠标光标来读取您需要绘制标签的位置。

使用这种方法,我可以获得用于绘制 2 个样本标签的近似(经纬度)位置。绘制它们的代码如下:

ax.text(-80.6, -57.0, '{0}\N{DEGREE SIGN} S '.format(57), va='center', ha='right',
                           transform=ccrs.PlateCarree())

ax.text(-75.15, -56.0, '{0}\N{DEGREE SIGN} W '.format(75), va='bottom', ha='center',
                           transform=ccrs.PlateCarree())

输出图将如下所示:

在此处输入图像描述


推荐阅读