[Tutor] problem in ploting cylinders with different colour.

Debashish Saha silideba at gmail.com
Tue Feb 14 14:13:49 CET 2012


import numpy

from enthought.mayavi import mlab

#def test_mesh():
#"""A very pretty picture of spherical harmonics translated from

#the octaviz example."""
for r in range (1,5):
    print r


    pi = numpy.pi

    cos = numpy.cos

    sin = numpy.sin

    dphi, dtheta, dz = pi/250.0, pi/250.0, 0.01

    #[phi,theta] = numpy.mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
    [phi,z] = numpy.mgrid[0:2*pi+dphi*1.5:dphi,0:2+dz*1.5:dz]

    m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;

   # r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + 5*sin(m4*theta)**m5 +
cos(m6*theta)**m7

    #x = 1*sin(phi)*cos(theta)

    #y = 1*sin(phi)*sin(theta)

    #z = 1*cos(phi);
    x=r*cos(phi)
    y=r*sin(phi)
    z=z
    i=['Reds','greens','autumn','purples']
    print i[r-1]
    e=i[r-1]

    mlab.mesh(x, y, z,colormap='e')
    #print i[r-1]

Error:
TypeError                                 Traceback (most recent call last)
C:\Python27\lib\site-packages\IPython\utils\py3compat.pyc in
execfile(fname, glob, loc)
    166             else:
    167                 filename = fname
--> 168             exec compile(scripttext, filename, 'exec') in glob, loc
    169     else:
    170         def execfile(fname, *where):

C:\Users\as\jhgf.py in <module>()
     24     print i[r-1]
     25     e=i[r-1]
---> 26     mlab.mesh(x, y, z,'e')
     27     #print i[r-1]

     28

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
the_function(*args, **kwargs)
     32 def document_pipeline(pipeline):
     33     def the_function(*args, **kwargs):
---> 34         return pipeline(*args, **kwargs)
     35
     36     if hasattr(pipeline, 'doc'):

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call__(self, *args, **kwargs)
     77             scene.disable_render = True
     78         # Then call the real logic

---> 79         output = self.__call_internal__(*args, **kwargs)
     80         # And re-enable the rendering, if needed.

     81         if scene is not None:

C:\Python27\lib\site-packages\mayavi\tools\helper_functions.pyc in
__call_internal__(self, *args, **kwargs)
    830         filters.
    831         """
--> 832         self.source = self._source_function(*args, **kwargs)
    833         kwargs.pop('name', None)
    834         self.store_kwargs(kwargs)

TypeError: grid_source() takes exactly 3 arguments (4 given)


More information about the Tutor mailing list