import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt # Define the equations def eq1(x, y, z): return (x**2 + y**2 - 1) * (x**2 + (x/3 - y/2)**2 - 1) * (y**2 + (x/3 - y/2)**2 - 1) - 1 def eq2(x, y, z): return (x**2 + y**2 - 1) * (x**2 + z**2 - 1) * (y**2 + z**2 - 1) - 1 def eq3(x, y, z): return x/3 - y/2 - z # Generate data x = np.linspace(-2, 2, 100) y = np.linspace(-2, 2, 100) z = np.linspace(-2, 2, 100) X, Y, Z = np.meshgrid(x, y, z) F1 = eq1(X, Y, Z) F2 = eq2(X, Y, Z) G = eq3(X, Y, Z) # Create figure and axes fig = plt.figure(figsize=(12, 8)) ax = fig.add_subplot(111, projection='3d') # Plot the surfaces ax.contour(X, Y, F1, levels=[0], colors='blue') ax.contour(X, Z, F2, levels=[0], colors='green') ax.contour(X, Y, G, levels=[0], colors='red') # Set axis labels and title ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_title('Three Surfaces in Space') # Show the plot plt.show()修改一下这段代码
时间: 2024-04-01 21:33:13 浏览: 49
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# Define the equations
def eq1(x, y, z):
return (x**2 + y**2 - 1) * (x**2 + (x/3 - y/2)**2 - 1) * (y**2 + (x/3 - y/2)**2 - 1) - 1
def eq2(x, y, z):
return (x**2 + y**2 - 1) * (x**2 + z**2 - 1) * (y**2 + z**2 - 1) - 1
def eq3(x, y, z):
return x/3 - y/2 - z
# Generate data
x = np.linspace(-2, 2, 100)
y = np.linspace(-2, 2, 100)
z = np.linspace(-2, 2, 100)
X, Y, Z = np.meshgrid(x, y, z)
F1 = eq1(X, Y, Z)
F2 = eq2(X, Y, Z)
G = eq3(X, Y, Z)
# Create figure and axes
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
# Plot the surfaces
ax.contour(X, Y, F1, levels=[0], colors='blue')
ax.contour(X, Z, F2, levels=[0], colors='green')
ax.contour(Y, Z, G, levels=[0], colors='red')
# Set axis labels and title
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Three Surfaces in Space')
# Show the plot
plt.show()
阅读全文