how to highlight points3d data

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

how to highlight points3d data

Ben Axelrod
I would like to display some data with points3d() of all the same color and size.  Then "highlight" some of the points by plotting larger, colored, semi-transparent points on the same graph.  Because mayavi combines the color and size property of points3d() I can't figure out how best to do this.  

The closest i have come is by using the scale_factor parameter.  However, the choice of the scale_factor is highly dependent on the range of the plotted data.  Is there any data-range independent way to do this?  Here is some sample code that demonstrates:

# sample code to highlight data points
import numpy as np
from numpy.random import rand
from enthought.mayavi import mlab

n = 10
factor = 10.0 #changing this makes the data not plotted as nice

xs = np.random.rand(n) * factor
ys = np.random.rand(n) * factor
zs = np.random.rand(n) * factor

mlab.points3d(xs, ys, zs, scale_factor = 1)
mlab.points3d(xs[:3], ys[:3], zs[:3], scale_factor = 1.5, color=(1,0,0), opacity = 0.5)

mlab.show()
#end code

Some other approaches i tried:
Specifying the fourth "s" parameter to be an array of all the same values.  This will specify the size of the points, then the color parameter will set the color.  However, even when i also specify vmin and vmax, mayavi does not seem to like it when all the values in the "s" array are the same value.  nothing gets plotted at all.  

I tried using the quiver3d and specifying the glyph color_mode and scale_mode as discussed here:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#adding-color-or-size-variations
But then the data point is not on the center of the sphere.

Any help?

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

Re: how to highlight points3d data

Gael Varoquaux
On Wed, Feb 03, 2010 at 01:58:15PM -0800, Ben Axelrod wrote:
> I tried using the quiver3d and specifying the glyph color_mode and scale_mode as discussed here:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#adding-color-or-size-variations
> But then the data point is not on the center of the sphere.

Ah, good point. Here is how you can center it:

x, y, z, s, c = np.random.random((5, 10))
pts = mlab.quiver3d(x, y, z, s, s, s, scalars=c, mode='sphere')
pts.glyph.color_mode = 'color_by_scalar'
pts.glyph.glyph_source.glyph_source.center = [0, 0, 0]

Could you confirm that it solves you problem, that way I can add it to
the documentation?

HTH,

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

Re: how to highlight points3d data

Ben Axelrod
Hi Gaël,

Thank you for the suggestion.  That did fix the quiver so now the points are centered around the data.  FYI, here is my test script.  It is slightly different than the code on the website.

#highlight data with quiver workaround
import numpy as np
from numpy.random import rand
from enthought.mayavi import mlab

n = 10
h = 3
xs = np.random.rand(n)
ys = np.random.rand(n)
zs = np.random.rand(n)
os = np.ones(n)

highdata = mlab.quiver3d(xs[:h], ys[:h], zs[:h],
                         os[:h], os[:h], os[:h],
                         scalars = 2 * os[:h],
                         vmin = 0,
                         vmax = 2,
                         mode = 'sphere',
                         color = (1,0,0),
                         opacity = 0.5)
highdata.glyph.scale_mode = 'scale_by_scalar'
highdata.glyph.glyph_source.glyph_source.center = [0, 0, 0]

data = mlab.quiver3d(xs, ys, zs,
                     os, os, os,
                     scalars = os,
                     vmin = 0,
                     vmax = 2,
                     mode = 'sphere',
                     color = (1,1,1))
data.glyph.scale_mode = 'scale_by_scalar'
data.glyph.glyph_source.glyph_source.center = [0, 0, 0]

mlab.show()
#end code

There is still a minor issue that the size of the data points is still somewhat dependent on the data.  for example, compare the relative size of the red and white spheres when n=10 and when n=1000.  But this is a minor issue.

Thanks again,
-Ben

________________________________________
From: [hidden email] [[hidden email]] On Behalf Of Gael Varoquaux [[hidden email]]
Sent: Wednesday, February 03, 2010 5:04 PM
To: [hidden email]
Subject: Re: [Enthought-Dev] how to highlight points3d data

On Wed, Feb 03, 2010 at 01:58:15PM -0800, Ben Axelrod wrote:
> I tried using the quiver3d and specifying the glyph color_mode and scale_mode as discussed here:
> http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#adding-color-or-size-variations
> But then the data point is not on the center of the sphere.

Ah, good point. Here is how you can center it:

x, y, z, s, c = np.random.random((5, 10))
pts = mlab.quiver3d(x, y, z, s, s, s, scalars=c, mode='sphere')
pts.glyph.color_mode = 'color_by_scalar'
pts.glyph.glyph_source.glyph_source.center = [0, 0, 0]

Could you confirm that it solves you problem, that way I can add it to
the documentation?

HTH,

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

Re: how to highlight points3d data

Gael Varoquaux
On Wed, Feb 03, 2010 at 02:29:44PM -0800, Ben Axelrod wrote:
> There is still a minor issue that the size of the data points is still
> somewhat dependent on the data.  for example, compare the relative size
> of the red and white spheres when n=10 and when n=1000.  But this is a
> minor issue.

Can you try fixing the scale_factor? I think what you are seeing is some
auto-adjusting of the scale.

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

Re: how to highlight points3d data

Ben Axelrod
If I hard-set the scale factor, then the sizes of the points are dependent on the range of the data.  Is there a way to determine the auto scale factor used in one plot so I can hard set it in another?
-Ben


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Gael Varoquaux
Sent: Wednesday, February 03, 2010 5:32 PM
To: [hidden email]
Subject: Re: [Enthought-Dev] how to highlight points3d data

On Wed, Feb 03, 2010 at 02:29:44PM -0800, Ben Axelrod wrote:
> There is still a minor issue that the size of the data points is still
> somewhat dependent on the data.  for example, compare the relative
> size of the red and white spheres when n=10 and when n=1000.  But this
> is a minor issue.

Can you try fixing the scale_factor? I think what you are seeing is some auto-adjusting of the scale.

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

Re: how to highlight points3d data

Gael Varoquaux
On Wed, Feb 03, 2010 at 02:48:20PM -0800, Ben Axelrod wrote:
> If I hard-set the scale factor, then the sizes of the points are dependent on the range of the data.  Is there a way to determine the auto scale factor used in one plot so I can hard set it in another?

pts.glyph.glyph.scale_factor

You can find all this information by using the GUI (the 'pipeline' that
pops up when you click on the Mayavi icon in the scenes). The names can
be usually guessed from the dialogs, and if non, there is the 'recording
mode', the red button in the pipeline dialog. See:
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/mlab.html#changing-object-properties-interactively
The UI has changed a bit since the screenshot was taken, but its still
the same idea.

HTH,

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