如何使seaborn.heatmap更大(正常大小)?

问题描述 投票:9回答:2

我在jupyter笔记本中用以下命令显示了情节:

sns.heatmap(pcts, annot=True, linewidth=.1, vmax=99, fmt='.1f', cmap='YlOrRd', square=True, cbar=False)
plt.yticks(list(reversed(range(len(indices)))), ['Index '+str(x) for x in indices], rotation='horizontal')
plt.title('Percentile ranks of\nsamples\' category spending');

得到了以下图片

heatmap with squares too small

即正方形看起来小得令人无法接受。

我怎样才能让它们更大?

python heatmap jupyter-notebook seaborn
2个回答
18
投票

在使用heatmap()之前,请使用matplotlib.pyplot.figure()参数调用figsize来设置图形的大小。例如:

pyplot.figure(figsize=(10, 16))
sns.heatmap(...)

传递给figsize的元组的两个元素是图形的所需宽度和高度(以英寸为单位)。然后,当您制作热图时,它会拉伸以填充给定大小的可用空间。您可能需要进行一些实验来确定最佳尺寸。


1
投票
import matplotlib.pyplot as plt

plt.figure(figsize=(12, 9))

sns.heatmap(df)
© www.soinside.com 2019 - 2024. All rights reserved.