我想使用seaborn生成带有24个子图的热图。最后,我想得到这样的东西:
我尝试使用以下代码:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage.filters import gaussian_filter
d1 = pd.read_csv('upper_POPC.txt', sep=" ", decimal=".")
d2 = pd.read_csv('upper_SDPE.txt', sep=" ", decimal=".")
d3 = pd.read_csv('upper_SDPS.txt', sep=" ", decimal=".")
d4 = pd.read_csv('upper_SAPI.txt', sep=" ", decimal=".")
d5 = pd.read_csv('upper_CDL2.txt', sep=" ", decimal=".")
d6 = pd.read_csv('upper_CHOL.txt', sep=" ", decimal=".")
heatmap_d1 = pd.pivot_table(d1, values='Value(s)', index=' X', columns='Y')
heatmap_d2 = pd.pivot_table(d2, values='Value(s)', index=' X', columns='Y')
heatmap_d3 = pd.pivot_table(d3, values='Value(s)', index=' X', columns='Y')
heatmap_d4 = pd.pivot_table(d4, values='Value(s)', index=' X', columns='Y')
heatmap_d5 = pd.pivot_table(d5, values='Value(s)', index=' X', columns='Y')
heatmap_d6 = pd.pivot_table(d6, values='Value(s)', index=' X', columns='Y')
smooth_d1 = gaussian_filter(heatmap_d1, sigma=1)
smooth_d2 = gaussian_filter(heatmap_d2, sigma=1)
smooth_d3 = gaussian_filter(heatmap_d3, sigma=1)
smooth_d4 = gaussian_filter(heatmap_d4, sigma=1)
smooth_d5 = gaussian_filter(heatmap_d5, sigma=1)
smooth_d6 = gaussian_filter(heatmap_d6, sigma=1)
fig, axes = plt.subplots(nrows=6, ncols=4, figsize=(12, 8), sharey=True)
p1 = sns.heatmap(smooth_d1, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[0,0])
p2 = sns.heatmap(smooth_d2, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[1,0])
p3 = sns.heatmap(smooth_d3, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[2,0])
p4 = sns.heatmap(smooth_d4, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[3,0])
p5 = sns.heatmap(smooth_d5, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[4,0])
p6 = sns.heatmap(smooth_d6, cmap="coolwarm", xticklabels=False, yticklabels=False, ax=axes[5,0])
输出:该代码不起作用,但是当我仅绘制一个数据集时,它将起作用。 可能的问题:问题在于将每个子图分配给数据集(p1,p2 ...)...我尝试了几个选项,但找不到正确的方法。使用Seaborn热图将数据分配给子图的最佳/清晰方法是什么?
注意: 此代码用于绘制我的数据的一部分。目的是在一列中绘制p1至p6。对于其余的列/行,一旦理解了数据的工作原理,便会添加数据。
谢谢!