Để vẽ đường cong 3D liên tục, ta dùng ax.plot(x, y, z) trên axes 3D với dữ liệu tham số.
Các bước
- Thiết lập figure size và autolayout.
- Tạo x, y bằng np.linspace, tính z = x² + y².
- Tạo figure và axes 3D.
- Vẽ đường 3D bằng ax.plot(x, y, z).
- Hiển thị bằng show().
Ví dụ
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-4 * np.pi, 4 * np.pi, 50)
y = np.linspace(-4 * np.pi, 4 * np.pi, 50)
z = x ** 2 + y ** 2
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x, y, z)
plt.show()
Kết quả
