ในการรวมสอง heatmaps ใน seaborn สามารถทำตามขั้นตอนดังนี้:
ขั้นตอน
ตั้งค่าขนาดรูปและปรับ padding ระหว่างและรอบ subplots
สร้างสอง Pandas data frames
สร้าง figure และชุด subplots ax1 และ ax2
วาด rectangular data as color-encoded matrix บน ax1 และ ax2
ย้าย ticks และ ticklabels (ถ้ามี) ไปขวาของ axes
รักษาความกว้าง padding ระหว่าง subplots น้อยที่สุด ส่วนของ average axes width
แสดงรูปด้วยเมธอด show()
ตัวอย่าง
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
df1 = pd.DataFrame(np.random.rand(10, 4), columns=list("ABCD"))
df2 = pd.DataFrame(np.random.rand(10, 4), columns=list("WXYZ"))
fig, (ax1, ax2) = plt.subplots(ncols=2)
fig.subplots_adjust(wspace=0.01)
sns.heatmap(df1, cmap="plasma", ax=ax1, cbar=False)
sns.heatmap(df2, cmap="hot", ax=ax2, cbar=False)
ax2.yaxis.tick_right()
fig.subplots_adjust(wspace=0.001)
plt.show()
ผลลัพธ์
จะแสดงสอง heatmaps ติดกัน ax1 plasma ax2 hot แกน Y ขวา wspace น้อยมาก
