如何在3D Python中的2个点之间绘制线

时间:2020-05-28 16:59:52

标签: python matplotlib

我在红点(网格)和蓝色三角形(站点)之间建立了一个模型,如下所示:

enter image description here

然后,我想画一条线连接红色点和6个最近的蓝色三角形。因此,每个红点都至少有6个蓝色三角形最接近它们。

我的数据中每个红色点和三角形都包含x,y,z

这是我用于绘图的代码(没有一行)

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#x =[1,2,3,4,5,6,7,8,9,10]
x = np.loadtxt("8krelok.txt")[:, 0] #long, lat, depth
y = np.loadtxt("8krelok.txt")[:, 1]
z = np.loadtxt("8krelok.txt")[:, 2]

x2 = np.loadtxt("stasiun.txt")[:, 0]
y2 = np.loadtxt("stasiun.txt")[:, 1]
z2 = np.loadtxt("stasiun.txt")[:, 2]

ax.scatter(x, y, z, c='r', marker='.', label = 'Grid')
ax.scatter(x2, y2, z2, c='b', marker='^', label = 'Station')

ax.set_xlabel('Longitude')
ax.set_ylabel('Latitude')
ax.set_zlabel('Depth')
ax.invert_zaxis()
plt.legend()
plt.show()

0 个答案:

没有答案
相关问题