如何使用seaborn生成高分辨率热图?

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

我有太多的相关特征(~100),导致图像分辨率低。如何提高分辨率?

sns.heatmap(Feature_corr, cbar = True,  square = True, annot=False,annot_kws={'size': 15},  cmap= 'coolwarm')
python heatmap seaborn
2个回答
12
投票

figure
之前从
matplotlib.pyplot
调用
heatmap
,并通过
figsize
设置图像大小,即:

import seaborn as sns
from matplotlib import pyplot

pyplot.figure(figsize=(15, 15)) # width and height in inches
sns.heatmap(Feature_corr, cbar=1, square=1, annot=0, annot_kws={'size': 15}, cmap= 'coolwarm')

6
投票

使用 Matplotlib 中的图形参数可以修改轴标签的宽度、高度、字体大小和 dpi。调整这些值可能有助于您的图像分辨率。

此外,您可以使用

annot_kws={"size": 8}
中的参数
sns.heatmap()
来修改值的字体大小。

DPI表示图中每英寸的像素数。较高的 DPI 值可提高分辨率。

上一个

corr = df2.corr() #your dataframe
sns.heatmap(corr, cmap="Blues", annot=True)

未经 Matplotlib 调整的结果图像

Result image without Matplotlib adjustments

使用 Matplotlib

import matplotlib.pyplot as plt
import seaborn as sns

corr = df2.corr() #your dataframe

# figsize=(6, 6) control width and height
# dpi = 600, I 
plt.figure(figsize=(6, 6), 
           dpi = 600) 
 
# parameter annot_kws={"size": 8} control corr values font size
sns.heatmap(corr, cmap="Blues", annot=True, annot_kws={"size": 8})

plt.tick_params(axis = 'x', labelsize = 12) # x font label size
plt.tick_params(axis = 'y', labelsize = 12) # y font label size

结果:

Example Image result with Matplotlib:

© www.soinside.com 2019 - 2024. All rights reserved.