import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
u=np.linspace(-2,2,100)
v=np.linspace(-2,2,100)
U,V=np.meshgrid(u,v)
X=U-(U**3)/3+U*V**2
Y=V-(V**3)/3+V*U**2
Z=U**2-V**2
fig=plt.figure(figsize=(6,6))
ax=fig.add_subplot(111,projection='3d')
ax.plot_surface(X,Y,Z,cmap='viridis',edgecolor='none',alpha=0.9)
ax.set_title('Enneper Surface')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
#source code --> clcoding.com
Code Explanation:
1. Import Libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
NumPy: For numerical operations and creating arrays.
Matplotlib.pyplot: For plotting graphs.
Axes3D: Enables 3D plotting capabilities.
2. Define Parameter Grid
u = np.linspace(-2, 2, 100)
v = np.linspace(-2, 2, 100)
U, V = np.meshgrid(u, v)
Creates two arrays u and v with 100 points each from
-2 to 2.
np.meshgrid creates coordinate matrices U and V for
all combinations of u and v. This forms a grid over which the surface is
calculated.
3. Calculate Coordinates Using Parametric Equations
X = U - (U**3)/3 + U*V**2
Y = V - (V**3)/3 + V*U**2
Z = U**2 - V**2
Computes the 3D coordinates of the Enneper surface
using its parametric formulas:
4. Create Figure and 3D Axis
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
Creates a new figure with size 10x8 inches.
Adds a 3D subplot to the figure for 3D plotting.
5. Plot the Surface
ax.plot_surface(X, Y, Z, cmap='viridis',
edgecolor='none', alpha=0.9)
Plots a 3D surface using the (X, Y, Z) coordinates.
Uses the 'viridis' colormap for coloring the surface.
Removes edge lines for a smooth look.
Sets surface transparency to 90% opacity for better visual depth.
6. Set Titles and Axis Labels
ax.set_title('Enneper Surface')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
Adds a title and labels to the X, Y, and Z axes.
7. Display the Plot
plt.show()
Shows the final 3D plot window displaying the
Enneper surface.


0 Comments:
Post a Comment