Matplotlib 3D hỗ trợ 2 loại chiếu: perspective (phối cảnh, vật xa nhỏ hơn) và orthographic (trực giao, kích thước không đổi theo khoảng cách). Chuyển đổi bằng ax.set_proj_type().
Các bước
- Thiết lập figure size và autolayout.
- Tạo figure.
- Thêm subplot 1: ax1 = fig.add_subplot(1,2,1, projection='3d'), set ax1.set_proj_type('persp').
- Thêm subplot 2: ax2 = fig.add_subplot(1,2,2, projection='3d'), set ax2.set_proj_type('ortho').
- Đặt tiêu đề cho từng subplot.
- Hiển thị bằng show().
Ví dụ
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1, projection='3d')
ax1.set_proj_type('persp')
ax1.set_title('Perspective')
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
ax2.set_proj_type('ortho')
ax2.set_title('Orthographic')
plt.show()
Kết quả
