Dear Gael, thank you for your fast answer. I manipulated the colormap, as you see below, but I am not sure it does what I wanted, because I do not understand exactly how the LUT works. I expected a smoother transition in the example below. This does not happens, since the value v in hsv is constant 1.
We can also compute the color of each computed point. Is there an efficient way to plot only the points with their associated colors? This will not look as good as mesh or surf, but it could be a start. Another approach would be if lut: [0,1] x [0,1] x [0,1] x [0,1] -> R x G x B x A instead of lut: [0,1] -> R x G x B x A scalar |-> (r,b,g,alpha) would be available, or even better, mesh(..., scalar1=?, scalar2=?, scalar3=?, scalar4=?) Any further ideas? Thanks, Vasile from numpy import linspace, pi, exp, angle, squeeze, zeros from matplotlib.colors import hsv_to_rgb from enthought.mayavi import mlab # 1) create a colormap which do what I think it should do: def compute_color_map(): # B. Thaller like convention k = linspace(-pi, pi, 256, endpoint=True) #unitcircle = exp(1.0j*k) #hsv_colors = zeros((1, unitcircle.shape[0], 3)) #hsv_colors[:,:, 0] = 0.5*(pi+angle(unitcircle))/pi hsv_colors = zeros((1, k.shape[0], 3)) hsv_colors[:,:, 0] = 0.5*(pi+k)/pi hsv_colors[:,:, 1] = 1.0 hsv_colors[:,:, 2] = 1.0 rgb_colors = hsv_to_rgb(hsv_colors) color_map = 255*squeeze(rgb_colors) return color_map # 2) define the ploting function def surfCF(gridx, gridy, phase, modulus, colormap=None): """Plot the modulus of a complex valued function $f:R^2 -> C$ together with its phase in a color coded fashion. @param grid: The grid nodes of the real domain R @param phase: The phase of the complex domain result f(grid) @param modulus: The modulus of the complex domain result f(grid) @keyword colormap: The colormap to use, if none is given, compute the 'default' QM colormap. """ if colormap is None: colormap = compute_color_map() mesh = mlab.mesh(gridx, gridy, modulus, scalars=phase, vmin=-pi, vmax=pi) # Set the custom color map lut = mesh.module_manager.scalar_lut_manager.lut.table.to_array() lut[:,0] = colormap[:,0] lut[:,1] = colormap[:,1] lut[:,2] = colormap[:,2] mesh.module_manager.scalar_lut_manager.lut.table = lut mlab.draw() return mesh # 3) then test it if __name__ == "__main__": from numpy import real, imag, conj, abs, mgrid x, y = mgrid[-2:2:0.05, -2:2:0.05] u = x*exp(-0.25*x**2) v = y*exp(-0.25*y**2) z = u*v surfCF(x, y, angle(z), abs(z)**2) ________________________________________ From: Gael Varoquaux [gael.varoqu...@normalesup.org] Sent: Thursday, June 09, 2011 7:43 AM To: enthought-...@enthought.com Cc: mayavi-users@lists.sourceforge.net Subject: Re: [MayaVi-users] [Enthought-Dev] complex valued function with "QM-standard" color convention? On Wed, Jun 08, 2011 at 12:04:38PM +0000, Gradinaru Vasile Catrinel wrote: > is that a map is defined with the help of the HLS color system > (hue-lightness-saturation): > - the hue of the color is given by angle(z) > - the lightness is given by absolute value of z (0 is white) > - the saturation is always maximal. > In case of complex functions depending on only one variable, I was able > to implement the same idea: just define the hsv_colors with this > convention (well, in 1D is the lightness also maximal) and convert them > to rgb_colors that we feed to the matplotlib routines, see below. > How should I implement this with mayavi2? Having a 2D colormap is not currently supported in Mayavi. If you want to define your own 1D colormap (that can then be called 'LUT' for Look Up Table), you can insert a pre-computed table, as can be seen in the following example: http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_custom_colormap.html Hope this helps, Gaƫl ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ MayaVi-users mailing list MayaVi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mayavi-users ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ MayaVi-users mailing list MayaVi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mayavi-users