Python 如何使 seaborn.heatmap 更大(正常大小)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41519991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make seaborn.heatmap larger (normal size)?
提问by Dims
I displayed plot with the following command in jupyter notebook:
我在 jupyter notebook 中使用以下命令显示了绘图:
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');
and got the following picture
并得到以下图片
i.e. squares appear unacceptably small.
即正方形显得小得令人无法接受。
How can I make them larger?
我怎样才能让它们变大?
回答by David Z
Before using heatmap()
, call matplotlib.pyplot.figure()
with the figsize
parameter to set the size of the figure. For example:
使用前heatmap()
,matplotlib.pyplot.figure()
带figsize
参数调用设置图形的大小。例如:
pyplot.figure(figsize=(10, 16))
sns.heatmap(...)
The two elements of the tuple passed to figsize
are the desired width and height of the figure in inches. Then when you make the heatmap, it will stretch to fill the available space given that size. You may have to do a bit of experimentation to determine what size looks best.
传递给元组的两个元素figsize
是所需的图形宽度和高度(以英寸为单位)。然后,当您制作热图时,它会拉伸以填充给定该大小的可用空间。您可能需要做一些实验来确定什么尺寸看起来最好。
回答by asmgx
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 9))
sns.heatmap(df)