0
我正在制作四面体分子的分子图,其中三个外部点(或原子)需要通过线连接到中心点。将点连接到三维散点上的中心点Python
从How can I connect points on a 3D scatter plot?我能够连接点,但它会产生不正确的线。
这是我的代码:
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, 1.2, 1.5, 1.5]
y = [1, 1.2, 2, 1.5, 1.5]
z = [.5, .5, .5, 1.2, 2]
a = []
b = []
c = []
for item in x:
a.append(float(item))
for item in y:
b.append(float(item))
for item in z:
c.append(float(item))
r = np.array(a)
s = np.array(b)
t = np.array(c)
ax.set_xlabel("x axis")
ax.set_ylabel("y axis")
ax.set_zlabel("z axis")
ax.scatter(r,s,zs = t, s=200)
ax.plot3D(r,s,z)
plt.show()
我想所有的点连接到中央点(x = 1.5,Y = 1.5,Z = 1.2)。以下是目前为止的样子: