使用Python在三维散点图中显示点旁边的坐标

使用Python在三维散点图中显示点旁边的坐标,python,matplotlib,3d,label,scatter-plot,Python,Matplotlib,3d,Label,Scatter Plot,我只想简单地显示这个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]

我只想简单地显示这个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()

谢谢。这么长的时间来提供一个更简单的代码演示。任何关于缩短它的意见都会很有帮助。

下面的例子是:


您可以更改zdir,为文本提供不同的方向。

您打算如何处理a、b、c和r、s、t?这只是从常规列表到浮点数数组的一步。可能重复的数据可以更简洁地定义为
x=np.array([1,1,2],dtype=float)
x=np.array([1,1,2.])
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')

# You can convert to float array in several ways
r = np.array([1, 1, 2], dtype=np.float)
s = np.array([float(i) for i in [1, 1, 2]])
t = np.array([1, 2, 2]) * 1.0

ax.scatter(r,s,zs = t, s=200, label='True Position')
for x, y, z in zip(r, s, t):
    text = str(x) + ', ' + str(y) + ', ' + str(z)
    ax.text(x, y, z, text, zdir=(1, 1, 1))

ax.set_xlabel("x axis")
ax.set_ylabel("y axis")
ax.set_zlabel("z axis")

plt.show()