-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_function.py
57 lines (42 loc) · 1.94 KB
/
plot_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
import cartopy.crs as ccrs
import cartopy.feature as cfeature
def point_overview(lat1: float, lon1: float, lat2: float, lon2: float):
'''
Plots points on world map.
Returns
-------
matplotlib figure
'''
central_lat = (lat1 + lat2)/2 + 20
central_lon = (lon1 + lon2)/2
# define map projection
map_proj = ccrs.Orthographic(central_latitude=central_lat, central_longitude=central_lon)
# set higher resolution for lines (the default values are awful)
map_proj._threshold /= 100.0
ax = plt.axes(projection=map_proj)
# plot entire globe
ax.set_global()
# add oceans & land
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.LAND)
# add labels
plt.text(lon1 - 2, lat1 - 10, s='Point A', backgroundcolor='white',
horizontalalignment='right', color='red', transform=ccrs.Geodetic())
plt.text(lon2 + 2, lat2 - 10, s='Point B', backgroundcolor='white',
horizontalalignment='left', color='red', transform=ccrs.Geodetic())
# North Pole lines for spherical triangle
line1 = mlines.Line2D(xdata=[lon1, 0], ydata=[lat1, 90], linestyle='--', transform=ccrs.Geodetic())
ax.add_line(line1)
line2 = mlines.Line2D(xdata=[lon2, 0], ydata=[lat2, 90], linestyle='--', transform=ccrs.Geodetic())
ax.add_line(line2)
# baseline of spherical triangle (between main points)
baseline = mlines.Line2D(xdata=[lon1, lon2], ydata=[lat1, lat2], color='pink',
marker='o', transform=ccrs.Geodetic())
ax.add_line(baseline)
# ellipsoidal chord is a straight line
chord = mlines.Line2D(xdata=[lon1, lon2], ydata=[lat1, lat2], color='red',
marker='o', transform=ccrs.PlateCarree())
ax.add_line(chord)
plt.show()