de mpl_toolkits.mplot3d importar axes3d de matplotlib.patches importar Circle importar matplotlib.pyplot como plt importar mpl_toolkits.mplot3d.art3d como art3d importar numpy como npR , r = 15 , 5def get_x ( phi , theta ): r global , R return ( R + r * np . cos ( phi )) * np . cos ( theta ) def get_y ( phi , theta ): r global , R return ( R + r * np . cos ( phi )) * np . pecado ( theta ) def get_z ( phi , theta ): global r return r * np . pecado ( phi )if __name__ == "__main__" : fig = plt . figura ( tamaño de la figura = ( 10 , 10 )) ax = fig . add_subplot ( 111 , proyección = '3d' ) ph = th = np . linspace ( - np . pi , np . pi , 30 ) phi , theta = np . cuadrícula ( ph , th ) x = np . array ([ get_x ( p , t ) para p , t en zip ( np . ravel ( phi ), np . ravel ( theta ))]) X = x . reshape ( phi . forma ) y = np . array ([ get_y ( p , t ) para p , t en zip ( np . ravel ( phi ), np . ravel ( theta ))]) Y = y . reshape ( phi . forma ) z = np . array ([ get_z ( p , t ) para p , t en zip ( np . ravel ( phi ), np . ravel ( theta ))]) Z = z . reshape ( phi . forma ) C1 = Círculo ( ( R , 0 ), radio = r , fc = 'none' , ec = 'rojo' ) C2 = Círculo ( ( 0 , 0 ), radio = R , fc = 'none ' , ec = ' magenta ' ) hacha . plot_wireframe ( X , Y , Z , color = '#CCCCCC' ) ax . add_patch ( C1 ) hacha . add_patch ( C2 ) art3d . pathpatch_2d_to_3d ( C1 , z = 0 , zdir = 'y' ) art3d . pathpatch_2d_to_3d ( C2 , z = r , zdir = 'z' ) hacha . set_xlim3d ( - 20 , 20 ) hacha . set_ylim3d ( - 20 , 20 ) hacha . set_zlim3d ( - 20 , 20 ) hacha . set_xlabel ( 'X' ) ax . set_ylabel ( 'Y' ) ax . set_zlabel ( 'Z' ) ax . set_axis_off () hacha . view_init ( elev = 30 , azim = - 45 ) plt . mostrar () plt . savefig ( 'torus.svg' , bbox_inches = 'apretado' , pad_inches =. 15 , \ bbox_extra_artists = [ C1 , C2 ], transparente = 'verdadero' )