问题
I use some shapefile data of the outline of Antartica in cartopy and this works fine. I can generate a plot with the shapefile and some more information on it. But I'm not able to plot the Longitude and Latitude information at the border of the image.
I use the orthographic projection with central_longitude and central_latitude.
I also need to mention that I'm comparably new to cartopy.
My code:
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()
With this I get the following plot (without the blue shapes):
Any help appreciated!
回答1:
If you run your code to produce interactive plot (using %matplotlib notebook
on jupyter notebook), you can move the mouse cursor to read the locations that you need to plot the labels.
With this method, I can get the approximate (long, lat) locations for plotting 2 sample labels. The code to plot them is as follows:
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())
And the output plot will look like this:
来源:https://stackoverflow.com/questions/58524585/how-to-plot-lon-lat-values-at-the-border-of-a-orthographic-cartopy-plot