Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Tùy chỉnh đường lưới (grid lines) cho Seaborn heatmap

Để tùy chỉnh độ dày và màu đường lưới ô vuông trong heatmap Seaborn, dùng tham số linewidths và linecolor trong sns.heatmap().

Các bước

  • Thiết lập figure size và autolayout.
  • Tạo DataFrame 5x5 ngẫu nhiên.
  • Vẽ heatmap với linewidths=4, linecolor='green'.
  • Hiển thị bằng show().

Ví dụ

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((5, 5)), columns=["col1", "col2", "col3", "col4", "col5"])
sns.heatmap(df, linewidths=4, linecolor='green')
plt.show()

Kết quả

Tùy chỉnh đường lưới (grid lines) cho Seaborn heatmap