Để vẽ heatmap cho 3 cột trong Python với Seaborn:
- Thiết lập kích thước figure và padding
- Tạo DataFrame
dfvới 3 cột - Vẽ ma trận mã hóa màu
- Hiển thị bằng
show()
Ví dụ mã nguồn
import seaborn as sns import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame(np.random.random((3, 3)), columns=["a", "b", "c"]) sns.heatmap(df, cbar=False) plt.show()
Kết quả
Heatmap 3x3 với 3 cột a, b, c, không hiển thị colorbar (cbar=False).

Tham số hữu ích:
annot=True- hiển thị giá trị trên ôfmt=".2f"- định dạng sốcmap="RdYlBu"- colormapcenter=0- trung tâm colormap tại 0linewidths=0.5- đường viền ô