Creating a Surface of Revolution

后端 未结 1 1736
慢半拍i
慢半拍i 2021-01-25 02:32

I have a 3d plot of a disk, here is the code:

ri = 100
ra = 300
h=20

# input xy coordinates
xy = np.array([[ri,0],[ra,0],[ra,h],[ri,h],[ri,0]])
# radial compone         


        
相关标签:
1条回答
  • 2021-01-25 02:53

    I'm not sure how you want to include your 2d plot, so here's how you do it as a surface of revolution.

    Your new_x corresponds to radial distance, new_y corresponds to height. So we need to generate an array of angles for which to generate the "cone":

    from matplotlib import cm
    
    tmp_phi = np.linspace(0,2*np.pi,50)[:,None] # angle data
    linesurf_x = new_x*np.cos(tmp_phi)
    linesurf_y = new_x*np.sin(tmp_phi)
    linesurf_z = np.broadcast_to(new_y, linesurf_x.shape)
    
    linesurf_c = np.broadcast_to(t, linesurf_x.shape) # color according to t
    colors = cm.jet(linesurf_c/linesurf_c.max()) # grab actual colors for the surface
    ax.plot_surface(linesurf_x, linesurf_y, linesurf_z, facecolors=colors,
                    rstride=1, cstride=1)
    

    Result:

    0 讨论(0)
提交回复
热议问题