Re: annotating many points with text in mayavi using mlab

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: annotating many points with text in mayavi using mlab

Patrick
Hi,

I'm trying to annotate points plotted with the points3d() function in mayavi.mlab. Each point is associated with a label which I would like to plot next to the points using the text3d() function. Plotting the points is fast, however the mlab.text3d() function does not seem to accept arrays of coordinates, so I have to loop over the points and plot 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 which shows the colours of the different labels (as for instance in matplotlib), I couldn't find anything in the docs.

Thanks,

Patrick

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: annotating many points with text in mayavi using mlab

Gael Varoquaux
On Wed, Oct 17, 2012 at 03:06:24PM +0100, Patrick wrote:
> I'm trying to annotate points plotted with the points3d() function in
> mayavi.mlab. Each point is associated with a label which I would like to plot
> next to the points using the text3d() function. Plotting the points is fast,
> however the mlab.text3d() function does not seem to accept arrays of
> coordinates, so I have to loop over the points and plot the text individually,
> which is very slow:

Sorry, Patrick, it seems that no body has great ideas to work around
this. I don't know of an underlying VTK actor or module that has multiple
text, which would have been useful here.

Gaël
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev