您无需地图投影即可获得所需的地球周围卫星图。三维绘图可用于创建地球,将地球图像覆盖在其周围,然后在地球表面上方绘制点。
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib.cbook import get_sample_data
from matplotlib._png import read_png
# Use world image with shape (360 rows, 720 columns)
pngfile = r"./eo_base_2020_clean_720x360.png"
fn = get_sample_data(pngfile, asfileobj=False)
img = read_png(fn) # get array of color
# Some needed functions / constant
r = 5
pi = np.pi
cos = np.cos
sin = np.sin
sqrt = np.sqrt
# Prep values to match the image shape (360 rows, 720 columns)
phi, theta = np.mgrid[0:pi:360j, 0:2*pi:720j]
# Parametric eq for a spherical globe
# phi=latitude; theta=longitude
x = r * sin(phi) * cos(theta)
y = r * sin(phi) * sin(theta)
z = r * cos(phi)
fig = plt.figure()
fig.set_size_inches(9, 9)
ax = fig.add_subplot(111, projection='3d', label='axes1')
# drape the image on the globe's surface
sp = ax.plot_surface(x, y, z, \
rstride=2, cstride=2, \
facecolors=img)
# plot some points above/around the globe
phi, theta = np.mgrid[0:pi:50j, 0:2*pi:50j]
r2 = 1.5*r
x = r2 * sin(phi) * cos(theta)
y = r2 * sin(phi) * sin(theta)
z = r2 * cos(phi) + 0.8* sin(sqrt(x**2 + y**2)) * cos(2*theta)
ax.scatter(x, y, z, s=1, color='red')
ax.set_axis_off()
ax.set_aspect(1)
plt.show()
地图投影是坐标变换
所有地图投影都是从地理位置到平面坐标系的转换函数集。实际实施需要一定的规则和范围以避免误用。我上面的代码可以被认为是在一个地方松散的 2 个地图投影。第一个地球仪使用 r=5 作为地球半径,该投影用于在投影平面上绘制 bluemarble 图像的像素。在共同位置的另一个地球仪使用半径 r2 = 1.5*r。它代表另一个投影,用于绘制可能是轨道地球卫星的点。
在一个axis 或Cartopy 或Basemap 上实现2 个叠加地图投影在技术上是可行的,在绘图过程中可以使用一些特殊的坐标变换。