2017-01-10 12 views
1

Я хотел бы просто отобразить координаты и рядом с каждой точкой этого 3D-рассеяния. Я видел это: Matplotlib: Annotating a 3D scatter plot, но вам нужно знать, как легко получить и отобразить КООРДИНАТЫ.Отображение координат рядом с точками в области 3D-рассеяния с помощью Python

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() 

Спасибо. Это так долго, чтобы предоставить более простое представление о том, что происходит с кодом. Любые мнения об их сокращении также будут полезны.

+0

Что вы намерены делать с a, b, c и r, s, t? – Lucas

+0

Это просто шаг за шагом, чтобы перейти из обычного списка в массив чисел с плавающей запятой. – peer

+2

Возможный дубликат [Matplotlib: аннотирование 3D-графика рассеяния] (http://stackoverflow.com/questions/10374930/matplotlib-annotating-a-3d-scatter-plot) – Julien

ответ

1

После примера mpl gallery:

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() 

text_in_3d_example

Вы можете изменить zdir дать разные направления к тексту.

 Смежные вопросы

  • Нет связанных вопросов^_^