Skip to content

How do create particle in Mayavi2

March 10, 2011

Particle:

A minute part or portion of matter; a morsel; a little bit; an atom; a jot; as, a particle of sand, of wood, of dust.

How to define particle in Mayavi?

In Mayavi, we can define a particle as glyphs (like points, arrows). It is very easy to plot a glyphs in Mayavi. Suppose, if we want to plot a points in mayavi, we have to provide two things that is ‘glyph type’ and ‘position’ where we have to plot.

How to plot?

enthought.mayavi.mlab  has a function called points3d which used to plot glyphs (like points) at the specified position

Function signatures:

points3d(x, y, z...)
points3d(x, y, z, s, ...)

x,y,z are the numpy arrays which are giving the position of the points. In addition we can pass 4th array s of the same shape of x,y,z  which giving the scalar value of each points.

For example, If we need the plot a single point

import numpy
from enthought.mayavi import mlab
mlab.figure(1, bgcolor=(0, 0, 0), size=(350, 350))
mlab.clf()
x = numpy.array([1])
y = numpy.array([1])
z = numpy.array([1])
mlab.points3d(x,y,z)
mlab.show()

Particle size:

The 4th argument of points3d function ‘s’ used to define particle size.  If all the particles are not same size , we need to give scalar value of each points. Take out the following example

x = [1, 2, 3, 4, 5, 6]
y = [0, 0, 0, 0, 0, 0]
z = y

If we represent a scalar varying from 0.5 to 1 on this dataset:

s = [.5, .6, .7, .8, .9, 1]

the scalar is mapped to diameter of the spheres

mlab.points3d(x, y, z, s)

the output will be

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: