船+无人机路径
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# 设置字体为中文,并解决负号显示问题。
plt.rcParams['font.family'] = ['SimHei']
matplotlib.rcParams['axes.unicode_minus'] = False
x = [0.0,11.639 , 121.968, 84.4327, 47.6534, 139.722, 107.493, 16.2922]
y = [0.0,93.4922, -144.528, -136.262, -19.6535, 183.839, -163.817, -47.9796]
s_x = [0.0,39.8522, 105.319, 92.1127, 27.7738, 113.242, 105.319, 29.3922]
s_y = [0.0,59.9459, -117.909, -124.857, -40.4328, 147.455, -117.909, -43.0551]
l_x = [0.0,51.6025, 92.1127, 86.6122, 20.9235, 131.624, 87.0351, 25.9646]
l_y = [0.0,75.4847, -124.857, -124.278, -29.701, 139.574, -124.816, -37.8691]
p_x = [39.8522, 51.6025, 105.319, 92.1127, 92.1127, 86.6122, 27.7738, 20.9235, 113.242, 131.624, 105.319, 87.0351, 29.3922, 25.9646]
p_y = [59.9459, 75.4847, -117.909, -124.857, -124.857, -124.278, -40.4328, -29.701, 147.455, 139.574, -117.909, -124.816, -43.0551, -37.8691]
# 自定义船只路径的坐标
ship_x = [0.0, 39.8522, 51.6025, 113.242, 131.624, 105.319, 105.319, 92.1127, 92.1127, 87.0351, 86.6122, 29.3922, 27.7738, 25.9646, 20.9235, 0.0] # 替换为你希望的船只 x 坐标列表
ship_y = [0.0,59.9459, 75.4847, 147.455, 139.574, -117.909, -117.909, -124.857, -124.857, -124.816, -124.278, -43.0551, -40.4328, -37.8691, -29.701,0.0] # 替换为你希望的船只 y 坐标列表
# 生成一个从 0 到 x 列表长度的整数数组。
n = np.arange(len(x))
# 绘制油田点的散点图
plt.plot(x, y, '.', c='black', label='油田点', marker="^", markersize=8)
# 在油田点上添加注释,注释内容为对应的数字,位置为坐标 (x[i], y[i]),注释文本的偏移为 (x[i] + 1, y[i] - 0.5)。
for i in range(len(n)):
plt.annotate(n[i], (x[i], y[i]), xytext=(x[i] + 1, y[i] - 0.5))
# 绘制无人机起降点和港口的散点图
plt.plot(s_x, s_y, '.', c='black', label='无人机起降点', marker="o", markersize=6)
plt.plot(l_x, l_y, '.', c='black', marker="o", markersize=6)
plt.plot(x[0], y[0], '.', marker="s", c='black', label='港口', markersize=8)
#定义了一个列表 OD1,包含需要连接的路径的索引。
OD1 = [1,2,3,4,5,6,7]
#绘制巡检船路径的线段,起点为 (x[0], y[0]),终点为 (s_x[OD1[0]], s_y[OD1[0]]),线段的颜色为黑色,添加标签为 "巡检船路径"。
# 并在终点处添加箭头注释,箭头起点为 (s_x[OD1[0]], s_y[OD1[0]]),终点为 (x[0], y[0])。
plt.plot([x[0], s_x[OD1[0]]], [y[0], s_y[OD1[0]]], c='black', label='巡检船路径')
#plt.annotate("", xy=(s_x[OD1[0]], s_y[OD1[0]]), xytext=(x[0], y[0]), arrowprops=dict(arrowstyle="->"))
for j in range(len(OD1)):
plt.plot([s_x[OD1[j]], x[OD1[j]]], [s_y[OD1[j]], y[OD1[j]]], c='black', linestyle='--')
plt.plot([x[OD1[j]], l_x[OD1[j]]], [y[OD1[j]], l_y[OD1[j]]], c='black', linestyle='--')
# 连接无人机起降点和港口,绘制船只路径
#plt.plot([s_x[0], l_x[0]], [s_y[0], l_y[0]], c='black')
# 连接无人机起降点和船只路径
#plt.plot([s_x[1], ship_x[0]], [s_y[1], ship_y[0]], c='black')
# 连接船只路径的各个坐标点
for j in range(len(ship_x) - 1):
plt.plot([ship_x[j], ship_x[j+1]], [ship_y[j], ship_y[j+1]], c='black')
# 连接船只路径和港口
#plt.plot([ship_x[-1], l_x[-1]], [ship_y[-1], l_y[-1]], c='black')
# 添加图例,设置图例的框架和列数,并显示图形。
plt.legend(frameon=False, ncol=2)
# 显示图形
plt.show()