Dear All, I want to visualize a function of two real variables with complex values, i.e. z = f(x,y) is complex with x, y real. Quite similar to the example on the atomic orbital
http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_atomic_orbital.html I want to plot a surface with height abs(z)**2; the color of the points on the surface should depend on the angle(z). In the example of the atomic orbital, the colormap='hsv' is used. I wasn't able to find out how the colormaps (particularly hsv), is defined. However, in the standard book of visualization in quantum mechanics (Bernd Thaller), the convention 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? Examples to try: g(x) = x*exp(-x**2) for x in [-1,1] should show two colors f(x,y) = g(x)*g(y) for x,y in [-1,1] should show two colors and no jumps, since white appears at x=0 or y=0 and the lightness vary smoothly (the RGBA has jumps...) Thank you, Vasile from numpy import pi, empty, array from matplotlib.colors import hsv_to_rgb from matplotlib.collections import LineCollection from matplotlib.pyplot import gca, plot def phaseplot(grid, phase, modulus, ax=None, label="", color="k", alpha=1.0, linestylep="solid", linestyle="solid", linewidthp=1, linewidth=1, marker="None"): """Plot the modulus complex valued function $f:R -> 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) """ # Color mapping hsv_colors = empty((1, len(grid), 3)) hsv_colors[:, :, 0] = 0.5*(pi+phase)/pi hsv_colors[:, :, 1] = 1.0 hsv_colors[:, :, 2] = 1.0 rgb_colors = hsv_to_rgb(hsv_colors) # Put all the vertical line into a collection segments = [ array([[node,0], [node,value]]) for node, value in zip(grid, modulus) ] line_segments = LineCollection(segments) # Set some properties of the lines rgb_colors = line_segments.to_rgba(rgb_colors) line_segments.set_color(rgb_colors[0]) line_segments.set_linestyle(linestylep) line_segments.set_linewidth(linewidthp) ------------------------------------------------------------------------------ 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 [email protected] https://lists.sourceforge.net/lists/listinfo/mayavi-users
