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

Dim*_*ims 9 python heatmap seaborn jupyter-notebook

我在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');
Run Code Online (Sandbox Code Playgroud)

得到了以下图片

正方形太小的热图

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

我怎样才能让它们更大?

Dav*_*d Z 19

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

pyplot.figure(figsize=(10, 16))
sns.heatmap(...)
Run Code Online (Sandbox Code Playgroud)

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


asm*_*mgx 6

import matplotlib.pyplot as plt

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

sns.heatmap(df)
Run Code Online (Sandbox Code Playgroud)