1
我想簡單地顯示這個3D散點上每個點的座標和旁邊的座標。我看過這個:Matplotlib: Annotating a 3D scatter plot,但需要知道如何輕鬆獲取並顯示座標。用Python顯示3D散點圖中點的座標
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, 1, 2]
y = [1, 1, 2]
z = [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))
print(a, b, c)
r = np.array(a)
s = np.array(b)
t = np.array(c)
print(r, s, t)
ax.set_xlabel("x axis")
ax.set_ylabel("y axis")
ax.set_zlabel("z axis")
ax.scatter(r,s,zs = t, s=200, label='True Position')
plt.show()
謝謝。提供關於代碼的更簡單的介紹,這是很長的。任何關於縮短它的意見也會有幫助。
你打算如何處理a,b,c和r,s,t? – Lucas
這只是一個從常規列表到浮點數數組的簡單步驟。 – peer
[Matplotlib:註釋3D散點圖]可能的重複(http://stackoverflow.com/questions/10374930/matplotlib-annotating-a-3d-scatter-plot) – Julien