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

2024-04-25 01:04:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我在jupyter笔记本中显示了plot命令:

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

也就是说,正方形看起来小得令人无法接受。

我怎样才能把它们变大?


Tags: 命令trueplot笔记本jupyterpltcmapsns
2条回答

在使用heatmap()之前,使用figsize参数调用^{}来设置图形的大小。例如:

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

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

import matplotlib.pyplot as plt

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

sns.heatmap(df)

相关问题 更多 >