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)。以下是目前爲止的樣子: