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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198 | import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib.patches import Rectangle
from matplotlib.collections import PatchCollection
import warnings
warnings.filterwarnings("ignore")
plt.rcParams["font.sans-serif"] = ["Arial Unicode MS", "DejaVu Sans", "SimHei"]
plt.rcParams["axes.unicode_minus"] = False
def create_sample_data():
np.random.seed(42)
regions = {
"north_america": {
"lon_range": (-130, -60),
"lat_range": (25, 55),
"n_points": 150,
"speed_bias": 100,
},
"europe": {
"lon_range": (-10, 40),
"lat_range": (35, 65),
"n_points": 120,
"speed_bias": 80,
},
"australia": {
"lon_range": (110, 155),
"lat_range": (-45, -10),
"n_points": 80,
"speed_bias": 100,
},
"south_america": {
"lon_range": (-80, -35),
"lat_range": (-55, 10),
"n_points": 60,
"speed_bias": 50,
},
"africa": {
"lon_range": (10, 50),
"lat_range": (-30, 30),
"n_points": 40,
"speed_bias": 30,
},
"asia": {
"lon_range": (70, 140),
"lat_range": (20, 60),
"n_points": 80,
"speed_bias": 60,
},
}
all_lons = []
all_lats = []
all_speeds = []
for region_name, region_data in regions.items():
n = region_data["n_points"]
lon_min, lon_max = region_data["lon_range"]
lat_min, lat_max = region_data["lat_range"]
bias = region_data["speed_bias"]
lons = np.random.uniform(lon_min, lon_max, n)
lats = np.random.uniform(lat_min, lat_max, n)
speeds = np.random.exponential(bias, n)
speeds = np.random.exponential(bias, n)
all_lons.extend(lons)
all_lats.extend(lats)
all_speeds.extend(speeds)
return np.array(all_lons), np.array(all_lats), np.array(all_speeds)
def get_speed_category(speeds):
colors = []
categories = []
for speed in speeds:
if speed < 25:
colors.append("#7FC8F8")
categories.append("slow")
elif speed < 100:
colors.append("#FFA500")
categories.append("medium")
else:
colors.append("#90EE90")
categories.append("fast")
return colors, categories
def plot_coverage_map(
lons,
lats,
speeds,
title="Average throughput at each distinct location\nof Starlink NDT speed tests",
figsize=(14, 8),
save_path=None,
):
"""绘制地理覆盖图
参数:
- lons: 经度数组
- lats: 纬度数组
- speeds: 速度数组(Mbps)
- title: 图表标题
- figsize: 图表大小
- save_path: 保存路径(可选)
"""
fig = plt.figure(figsize=figsize)
ax = plt.axes(projection=ccrs.PlateCarree())
# 设置地图范围(全球)
ax.set_global()
# 添加地图特征
# 添加陆地(浅灰色填充)
ax.add_feature(cfeature.LAND, facecolor="#F5F5F5", edgecolor="none", zorder=1)
# 添加海洋(白色)
ax.add_feature(cfeature.OCEAN, facecolor="white", zorder=0)
# 添加国家边界(黑色细线)
ax.add_feature(cfeature.BORDERS, linewidth=0.5, edgecolor="#333333", zorder=2)
# 添加海岸线
ax.coastlines(linewidth=0.8, color="#333333", zorder=2)
# 获取颜色分类
colors, categories = get_speed_category(speeds)
# 绘制散点: 使用较小的点和一定的透明度来处理重叠
scatter = ax.scatter(
lons,
lats,
c=colors,
s=20, # 点的大小
alpha=0.6, # 透明度
edgecolors="none",
transform=ccrs.PlateCarree(),
zorder=3,
)
# 添加图例
from matplotlib.patches import Patch
legend_elements = [
Patch(facecolor="#7FC8F8", label="[0,25) Mbps"),
Patch(facecolor="#FFA500", label="[25,100) Mbps"),
Patch(facecolor="#90EE90", label="[100,∞) Mbps"),
]
# 将图例放在左下角
ax.legend(
handles=legend_elements,
loc="lower left",
frameon=True,
facecolor="white",
edgecolor="black",
fontsize=10,
title="Mbps",
)
# 添加标题
plt.title(title, fontsize=14, fontweight="bold", pad=20)
# 调整布局
plt.tight_layout()
# 保存图形
if save_path:
plt.savefig(save_path, dpi=300, bbox_inches="tight", facecolor="white")
print(f"图形已保存到: {save_path}")
return fig, ax
def main():
lons, lats, speeds = create_sample_data()
print(f"生成了 {len(lons)} 个测试点")
print(f"速度范围: {speeds.min():.2f} - {speeds.max():.2f} Mbps")
fig1, ax1 = plot_coverage_map(
lons, lats, speeds, save_path="./starlink_coverage_detailed.png"
)
plt.show()
if __name__ == "__main__":
main()
|