how do you radially 'sweep out' a 1D array to plot 3d figure in python? (to represent a wavefunction)

前端 未结 2 1906
萌比男神i
萌比男神i 2021-02-11 06:50

effectively I have a large 1D array of heights. As a small example consider:

u=array([0,1,2,1,0,2,4,6,4,2,1])

and a 1D array, the same size as

2条回答
  •  梦谈多话
    2021-02-11 07:03

    You're better off with something more 3D oriented than matplotlib, in this case...

    Here's a quick example using mayavi: alt text

    from enthought.mayavi import mlab
    import numpy as np
    
    # Generate some random data along a straight line in the x-direction
    num = 100
    x = np.arange(num)
    y, z = np.ones(num), np.ones(num)
    
    s = np.cumsum(np.random.random(num) - 0.5)
    
    # Plot using mayavi's mlab api
    fig = mlab.figure()
    
    # First we need to make a line source from our data
    line = mlab.pipeline.line_source(x,y,z,s)
    
    # Then we apply the "tube" filter to it, and vary the radius by "s"
    tube = mlab.pipeline.tube(line, tube_sides=20, tube_radius=1.0)
    tube.filter.vary_radius = 'vary_radius_by_scalar'
    
    # Now we display the tube as a surface
    mlab.pipeline.surface(tube)
    
    # And finally visualize the result
    mlab.show()
    

提交回复
热议问题