Python 在 3D 散点图中注释点 [英] Python annotating points in a 3D scattter plot
本文介绍了Python 在 3D 散点图中注释点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为数据中的每个点(3D)和标签(标签是字典中的键)提供标签:
I want to give labels to each point (3D) in my data and the labels (the labels are keys in a dictionary) :
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()
我的输入:
arrayx:
[[0.7], [7.1], [7.5], [0.6], [0.5], [0.00016775708773695687]...]
阵列:
[[0.1], [2], [3], [6], [5], [16775708773695687]...]
数组:
[1], [2], [3], [4], [5], [6]...]
并为图中的每个点 3D 打上标签
And give a label to each point 3D in the graph
推荐答案
从@martin-evans 的答案中借用了代码,但使用了 zip
borrowing from @martin-evans's answer for the code, but using zip
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
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_label, y_label, z_label, label in zip(arrayx, arrayy, arrayz, labels):
ax3d.text(x_label, y_label, z_label, label)
plt.title("Data")
plt.show()
这篇关于Python 在 3D 散点图中注释点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文