Hi, I still not have a solution for plotting the complex valued functions with mayavi. It is not clear to me whether there is an issue of VTK itself or of a not-yet-implemented function in mayavi. However, I was able to do exactly what I wanted using matplotlib; unfortunately, this has to stay 2D. I was hoping to be able to do something similar for 3-dimensional functions in mayavi...
Here is the exercise: given the function f(x,y) = (-1.+(x+1.j*y)**3)**2 we have to plot z = f(x,y) for x an y between -2 and 2. As z is complex, we follow the convention of Thaller (quantum mechanics): the color of each point is first computed in the hsv system, where h (hue) is given by the angle of z, s is always 1 and v (value) is related to the absolute value of z (by the stereographic projection) such that a point of absolute value 0 is completely dark. After that, the hsv codes are traduced into the rgb system and then the points with their own colors are ploted with the imshow function of matplotlib. The proposed function to plot is nice, because we'll recognize 3 dark points: it has 3 zeros. The phase spectrum appears 2 times around each dark point, meaning that each of the zeros has multiplicity 2. If you run the implementation below (which uses matplotlib), you'll agree, I hope, that such a visualization is more helpful that a classical one, and hence it is worthwhile to find a solution in mayavi, too... Would it be possible in mayavi to plot only the points, but each with its own color and without modifying their size? Vasile ---------- from matplotlib.colors import hsv_to_rgb import numpy as np # create the grid x, y = np.mgrid[-2:2:0.01, -2:2:0.05] z = -1.+(x+1.j*y)**3 z = z**2 # function to be ploted # funny think in matplotlib: the axes are inversed :( z = z.transpose(); x = x.transpose(); y = y.transpose() # go for the hue from the phase phase = np.angle(-z) # to get exactly Thallers colors A = 0.5*(phase+np.pi)/np.pi # go for the value in the hsv scheme R = abs(z)**2; M = 0.1#R.min() # M is needed in the projection theta = np.pi - 2*np.arctan(np.sqrt(R/M)) # prepare the points to be ploted Nx,Ny = z.shape hsv_colors = np.empty((Nx, Ny,3)) hsv_colors[:, :, 0] = A hsv_colors[:, :, 1] = 1. hsv_colors[:, :, 2] = 1.-theta/np.pi z_rgb = hsv_to_rgb(hsv_colors) # and plot them import matplotlib.pyplot as plt fig = plt.figure() plt.imshow(z_rgb, origin='lower', extent=[-2,2,-2,2]) plt.xlabel('x') plt.ylabel('y') fig = plt.figure() # look only at the absolute value plt.imshow(R, origin='lower', extent=[-2,2,-2,2]) plt.xlabel('x') plt.ylabel('y') plt.show() ________________________________________ From: Gradinaru Vasile Catrinel [vasile.gradin...@sam.math.ethz.ch] Sent: Friday, June 10, 2011 11:44 AM To: Gael Varoquaux Cc: enthought-...@enthought.com; mayavi-users@lists.sourceforge.net Subject: Re: [MayaVi-users] [Enthought-Dev] complex valued function with "QM-standard" color convention? Hi, having only 0 and pi is just what I wanted: a simple example allows me to find faster the bugs... Since the v in the hsv scheme is constant (hue-saturation-value) we see the jump. Having the v set by the (squared) absolute value of z=f(x,y) would allow the points near to 0 to be darker and maybe to not allow the eyes to realize too much of the jump. Do you know if there is an efficient way to plot only the points with their associated colors (each point comes with its own color)? Vasile ________________________________________ From: Gael Varoquaux [gael.varoqu...@normalesup.org] Sent: Friday, June 10, 2011 9:01 AM To: Gradinaru Vasile Catrinel Cc: enthought-...@enthought.com; mayavi-users@lists.sourceforge.net Subject: Re: [MayaVi-users] [Enthought-Dev] complex valued function with "QM-standard" color convention? Hi, I had a quick look at your code, and it seems jst fine. It even seems to run fine, at least the Mayavi part. The 'angle(z)' variable that you are passing in is only made of 0 and pi values, thus I am not surprised that the mesh shows only two colors. Maybe that's where the problem lies? Cheers, Gael On Thu, Jun 09, 2011 at 03:00:36PM +0000, Gradinaru Vasile Catrinel wrote: > 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) ------------------------------------------------------------------------------ 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 ------------------------------------------------------------------------------ Simplify data backup and recovery for your virtual environment with vRanger. Installation's a snap, and flexible recovery options mean your data is safe, secure and there when you need it. Data protection magic? Nope - It's vRanger. Get your free trial download today. http://p.sf.net/sfu/quest-sfdev2dev _______________________________________________ MayaVi-users mailing list MayaVi-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mayavi-users