From: Romain M. <rom...@ce...> - 2015-07-10 11:54:18
|
Dear experts, I am trying to plot spherical harmonics with matplotlib and I have some troubles. I am starting from the example http://matplotlib.org/examples/mplot3d/surface3d_demo2.html where I change the factor 10 in a function of r=f(theta,phi) (or r=f(u,v) as they are named in the example). I observe very strange behaviours: (1) (x,y,z) = (r cos(phi) sin(theta) , r sin(phi) sin(theta) , r cos(theta)). But np.outer(a,b) is not commutative while the multiplication is. So how to choose the order in the np.outer() product? In fact, different order gives very different results. (2) It's seem impossible to reproduce the well known Ylm(theta,phi) plots. Using for example this document http://www.cs.dartmouth.edu/~wjarosz/publications/dissertation/appendixB.pdf : I don't know if I am doing something wrong or so, but I don't understand ... My full code is bellow. Thanks a lot in advance ! Cheers, Romain PS: import math import numpy as np import pylab as p from mpl_toolkits.mplot3d import Axes3D def f(theta,phi): return np.sin(phi)*np.cos(phi)*np.sin(theta)**2 fig = p.figure() ax = fig.add_subplot(111, projection='3d') theta = np.linspace(0, np.pi, 500) phi = np.linspace(0, 2*np.pi, 500) r = f(theta,phi) x = r**2 * np.outer( np.cos(phi) , np.sin(theta) ) y = r**2 * np.outer( np.sin(phi) , np.sin(theta) ) z = r**2 * np.outer(np.ones(phi.shape), np.cos(theta)) #x = r**2 * np.outer( np.sin(theta) , np.cos(phi) ) #y = r**2 * np.outer( np.sin(theta) , np.sin(phi) ) #z = r**2 * np.outer( np.cos(theta), np.ones(theta.shape) ) ax.plot_surface(x,y,z) ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_zlabel("Z") p.show() -- ========================================================= Romain Madar Laboratoire de Physique Corpusculaire de Clermont-Ferrand Campus Universitaire des Cézeaux 4 avenue Blaise Pascal TSA 60026, CS 60026 63178 Aubière cedex, FRANCE Email: rom...@ce... Tel. : +33 (0)4 73 40 71 57 Off. : 8204-8205 ========================================================= |