Python: How can I plot a generic 3D object if I have x, y and z as functions of some parameters?
Question: For instance, for the unit sphere, one has

    
    
    x = cos(phi)sin(theta)
    y = sin(phi)sin(theta)
    z = cos(theta)
    

I would like to simply plot the set of points where phi and theta are in the
intervals `[0, 2*pi]` and `[0, pi]`, respectively.

Is there a way to do this in the general case, meaning specifying

  * x,y,z as functions of some parameters, and
  * The ranges of those parameters

and then getting a 3D plot of that?


Answer: I think as far as Mayavi goes, you will always be stuck with creating some
grids yourself, and plotting the resulting datapoints... This does, however,
not have to be too cumbersome when using numpy :

    
    
    from numpy import pi, sin, cos, mgrid
    [phi,theta] = mgrid[0:2*pi:100j,0:pi:100j]  # 100 is the amount of steps in the respective dimension
    x = cos(phi)*sin(theta)
    y = sin(phi)*sin(theta)
    z = cos(theta)
    
    from mayavi import mlab
    s = mlab.mesh(x, y, z)
    mlab.show()
    

