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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

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
@hadik Is there something wrong with using a loop? Seems pretty compact to me.
it is fine but i was wondering if there were other inbuilt functions that did it directly. Thanks for the reply though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.