I am trying to annotate points constructed using points3d () function using mayavi.mlab. Each point is associated with a label that I would like to build next to the points using the text3d () function. Building points is fast, but the mlab.text3d () function does not seem to accept coordinate arrays, so I have to iterate over the points and print the text individually, which is very slow:
for i in xrange(0, self.n_labels): self.mlab_data.append( mlab.points3d( pX[self.labels == self.u_labels[i], 0], pX[self.labels == self.u_labels[i], 1], pX[self.labels == self.u_labels[i], 2], color=self.colours[i], opacity=1, scale_mode="none", scale_factor=sf ) ) idcs, = np.where(self.labels == self.u_labels[i]) for n in idcs.flatten(): mlab.text3d( pX[n, 0], pX[n, 1], pX[n, 2], "%d" % self.u_labels[i], color=self.colours[i], opacity=1, scale=sf )
Any ideas how I could speed this up? Also, is it possible to add a legend (for example, in matplotlib), I could not find anything in the documents.
Thanks,
Patrick
source share