import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt def eq1(x, y, z): return ((x**2 + y**2 - 1) * (x**2 + (x**3/3 - y**2/2)**2 - 1) * (y**2 + (x**3/3 - y**2/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/3 - y**2/2 - z) 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) fig = plt.figure(figsize=(12, 8)) ax = fig.add_subplot(111, projection='3d') 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') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_title('Three Surfaces in Space') plt.show()修改一下这段代码
时间: 2023-12-18 17:28:07 浏览: 252
import numpy as np import matplotlib.pyplot as plt import math
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def eq1(x, y, z):
return ((x**2 + y**2 - 1) * (x**2 + (x**3/3 - y**2/2)**2 - 1) * (y**2 + (x**3/3 - y**2/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/3 - y**2/2 - z)
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)
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
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')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Three Surfaces in Space')
plt.show()
阅读全文