Python 注释 3D 散点图中的点

eri*_*ja 2 python scatter-plot

我想为数据中的每个点(3D)和标签提供标签(标签是字典中的键):

l = list(dictionary.keys())
#transform the array to a list
arrayx=arrayx.tolist()
arrayy=arrayy.tolist()
arrayz=arrayz.tolist()
#arrayx contains my x coordinates
ax.scatter(arrayx, arrayy, arrayz)
#give the labels to each point
for  label in enumerate(l):
    ax.annotate(label, ([arrayx[i] for i in range(27)],[arrayy[i]for i in range(27)],[arrayz[i] for i in range(27)]))
plt.title("Data")
plt.show()
Run Code Online (Sandbox Code Playgroud)

我的输入:

数组x:

[[0.7], [7.1], [7.5], [0.6], [0.5], [0.00016775708773695687]...]
Run Code Online (Sandbox Code Playgroud)

阵列:

[[0.1], [2], [3], [6], [5], [16775708773695687]...]
Run Code Online (Sandbox Code Playgroud)

数组z:

[1], [2], [3], [4], [5], [6]...]
Run Code Online (Sandbox Code Playgroud)

并为图中的每个点 3D 贴上标签

Mar*_*ans 5

您可以向每个点添加文本,如下所示:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

ax3d = plt.figure().gca(projection='3d')

arrayx = np.array([[0.7], [7.1], [7.5], [0.6], [0.5], [0.00016775708773695687]])
arrayy = np.array([[0.1], [2], [3], [6], [5], [16775708773695687]])
arrayz = np.array([[1], [2], [3], [4], [5], [6]])

labels = ['one', 'two', 'three', 'four', 'five', 'six']

arrayx = arrayx.flatten()
arrayy = arrayy.flatten()
arrayz = arrayz.flatten()

ax3d.scatter(arrayx, arrayy, arrayz)

#give the labels to each point
for x, y, z, label in zip(arrayx, arrayy, arrayz, labels):
    ax3d.text(x, y, z, label)

plt.title("Data")
plt.show()
Run Code Online (Sandbox Code Playgroud)

这将为您提供以下输出:

3d 散点图