pythonmatplotlibplotsurface

Revolution of a curve around the y axis in python


So i have the curve y=1-785848464864864864848484848484848484


Solution

  • A better naming convention would help you: what you have called x is really going to be a radius r in your plot, whilst what you have called y is actually going to be an angle, phi. So you really have polar coordinates (in x-z planes), with

    x = r cos(phi)

    z = r sin(phi)

    y = 1 - (r-1)^2

    import numpy as np
    import matplotlib.pyplot as plt
    
    r = np.linspace( 1.0, 2.0, 100 )
    phi = np.linspace( 0.0, 2 * np.pi, 100 )
    R, PHI = np.meshgrid( r, phi )
    
    X = R * np.cos( PHI )
    Z = R * np.sin( PHI )
    Y = 1 - ( R - 1 ) ** 2
    
    fig = plt.figure()
    ax = fig.add_subplot( 1, 1, 1, projection='3d')
    ax.plot_surface( X, Y, Z, alpha=0.3, color='red' )
    ax.view_init( 45, 45 )
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')
    plt.ylim(-1, 3)
    plt.show()
    

    enter image description here