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