在同一平面中的两个窗口分别画出心形线和马鞍面代码
时间: 2024-05-14 22:12:26 浏览: 178
matlab马鞍面的数据
心形线代码:
```python
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2*np.pi, 1000)
x = 16*np.sin(t)**3
y = 13*np.cos(t) - 5*np.cos(2*t) - 2*np.cos(3*t) - np.cos(4*t)
fig, ax = plt.subplots()
ax.plot(x, y, color='red')
ax.set_aspect('equal')
plt.show()
```
马鞍面代码:
```python
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.linspace(-2, 2, 100)
y = np.linspace(-2, 2, 100)
x, y = np.meshgrid(x, y)
z = x**2 - y**2
ax.plot_surface(x, y, z, cmap='viridis')
plt.show()
```
阅读全文