Để lưu biểu đồ 3D xoay trong Matplotlib:
- Thiết lập kích thước hình và điều chỉnh khoảng đệm subplot.
- Tạo figure mới hoặc kích hoạt figure hiện có.
- Thêm axes 3D vào figure.
- Lấy bộ dữ liệu test X, Y, Z.
- Vẽ wireframe 3D.
- Xoay trục với góc angle.
- Vẽ lại figure hiện tại.
- Chạy vòng lặp GUI event vài giây.
- Hiển thị hình bằng show().
Ví dụ
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.1)
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)
for angle in range(0, 360):
ax.view_init(30, angle)
plt.draw()
plt.pause(.001)
plt.show()
Kết quả
