Để vẽ histogram 3D (các cột 3D), ta dùng phương thức bar3d() trên axes 3D.
Các bước
- Thiết lập figure size và autolayout.
- Tạo figure và thêm axes 3D.
- Tạo tọa độ gốc (x3, y3, z3) và kích thước (dx, dy, dz) cho các cột.
- Vẽ cột 3D bằng bar3d().
- Tắt axes bằng axis('off').
- 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
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
x3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y3 = [5, 6, 7, 8, 2, 5, 6, 3, 7, 2]
z3 = np.zeros(10)
dx = np.ones(10)
dy = np.ones(10)
dz = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ax1.bar3d(y3, x3, z3, dx, dy, dz, color="red")
ax1.axis('off')
plt.show()
Kết quả
