2015-10-13 274 views
12

当使用seaborn热图时,是否有一种方法可以自动调整字体大小以使其完全适合正方形? 例如:自动调整seaborn热图中的字体大小

这里的大小是在 “annot_kws” 设置。

+1

没有按比例绘制的字体;它依靠太多的东西来可靠地预测。 – mwaskom

+0

谢谢@mwaskom – Gabriel

+7

感谢您使用'annot_kws = {“size”:8}'!正是我在找的东西:)。 – ostrokach

回答

0

尽管扭曲了热图,此实施例举例说明了如何使用.set(...)上下文

import matplotlib.pyplot as plt 
import seaborn as sns 
sns.set(font_scale=3) 

# Load the example flights dataset and conver to long-form 
flights_long = sns.load_dataset("flights") 
flights = flights_long.pivot("month", "year", "passengers") 

# Draw a heatmap with the numeric values in each cell 
f, ax = plt.subplots(figsize=(9, 6)) 
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax) 
f.savefig("output.png")