使用seaborn facetgrid heatmap更改构面标题的字体大小 [英] change font size of facet titles using seaborn facetgrid heatmap

查看:85
本文介绍了使用seaborn facetgrid heatmap更改构面标题的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这是一个不同于

解决方案

感谢@mwaskon,这就是答案-当被称为 set_titles 时,请使用 size = .

这会导致更多的问题,比如

  • 您能否更改使用 fontweight = fontsize = set_titles ,而不是fontweight=size=? size = 用于其他方面的刻面高度(以英寸为单位).
  • 为什么 sns.plotting_context 在这方面完全无效上下文?

Note: this is a different question than "How can I change the font size using seaborn FacetGrid?". The methods suggested there do not work when using a heatmap inside a facetgrid.

How can I change the font size of the facet titles when plotting heatmaps inside a facetgrid?

The code below tries two methods, passing fontsize= to set_titles() and wrapping the whole thing in a plotting context. As far as I can tell, neither seems to have any effect on facet titles when using heatmap, although the fontweight did change. Are there any other options for controlling facet title when using heatmap?

import pandas as pd
import numpy as np
import itertools
import seaborn as sns

print("seaborn version {}".format(sns.__version__))
# R expand.grid() function in Python
# https://stackoverflow.com/a/12131385/1135316
def expandgrid(*itrs):
   product = list(itertools.product(*itrs))
   return {'Var{}'.format(i+1):[x[i] for x in product] for i in range(len(itrs))}

methods=['method 1', 'method2', 'method 3', 'method 4']
times = range(0,100,10)
data = pd.DataFrame(expandgrid(methods, times, times))
data.columns = ['method', 'dtsi','rtsi']
data['nw_score'] = np.random.sample(data.shape[0])

def facet(data,color):
    data = data.pivot(index="dtsi", columns='rtsi', values='nw_score')
    g = sns.heatmap(data, cmap='Blues', cbar=False)

with sns.plotting_context(font_scale=5.5):
    g = sns.FacetGrid(data, col="method", col_wrap=2, size=3, aspect=1)
    g = g.map_dataframe(facet)
    g.set_titles(col_template="{col_name}", fontweight='bold', fontsize=18)

解决方案

Thanks @mwaskon, that is the answer - use size= when called set_titles.

That leads to more questions, like

  • Can you please change set_titles used fontweight= and fontsize= instead of fontweight= and size=? size= is use elsewhere for the facet height in inches.
  • why is sns.plotting_context completely ineffective in this context?

这篇关于使用seaborn facetgrid heatmap更改构面标题的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆