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