0

I am trying to draw a simple 3D polyhedron and trying to label the vertices with the coordinates. First step I want do is simply label each vertices with their order or 1, 2, ...

I saw in this answer where I can use loop to do so. But I was wondering if there was possibility to pass on the list of x,y,z coordinates and a list of labels and it will simply plot the points and label it, possibly without any loop. If there exist such functions that I am not aware of.
This is what i have till now

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D 
#coord = 10*np.random.rand(3,num)#num points in 3D #first axis is x, second = y, third = z
xcod = np.array([1,2,3,2.7,2.4,1])
ycod = np.array([1,1,4,5.,6,1])
zcod = np.array([1,2,1,2,3,1])
#coord = np.concatenate(coord,coord[0])
#####plotting in 3d
fig = plt.figure()
ax = fig.add_subplot(111,projection = '3d')
#plotting all the points
ax.plot(xcod,ycod,zcod,'x-')
#adding labels for vertice
#ax.text(xcod,ycod,zcod,["1","2","3","4","5","6","7"])
#supposed centroid
ax.scatter(np.mean(xcod),np.mean(ycod),np.mean(zcod),marker = 'o',color='g')
ax.set_xlabel("x axis")
ax.set_ylabel("y axis")
ax.set_zlabel("z axis")

plt.show()

enter image description here

I tried with ax.text(xcod,ycod,zcod,["1","2","3","4","5","6"]) which did not work. I could follow the loop but is there another simple way to do it?

Community
  • 1
  • 1
jkhadka
  • 2,443
  • 8
  • 34
  • 56

1 Answers1

3

ax.text() only places text in one position.

Try:

for x,y,z,i in zip(xcod,ycod,zcod,range(len(xcod))):
    ax.text(x,y,z,i)

then you get:

enter image description here

M.T
  • 4,917
  • 4
  • 33
  • 52
  • hey, yeah i did this but was wondering if there was a function that may not know about that takes a list of x,y,z and a list of labels and basically does that without loop – jkhadka Feb 19 '16 at 13:24
  • @hadik Is there something wrong with using a loop? Seems pretty compact to me. – M.T Feb 19 '16 at 13:26
  • it is fine but i was wondering if there were other inbuilt functions that did it directly. Thanks for the reply though :) – jkhadka Feb 19 '16 at 13:34