2014-10-01 31 views
7

当使用Seaborn facetGrid图时。是否可以将行变量标签设置为左侧(例如,作为两行子图的第一行y轴标签)?Python seaborn facetGrid:是否可以将行分类标签位置设置为左侧

默认位置在顶部作为子图标题的一部分。不幸的是,合并后的文本有时会过长,无法合理地融入这个拥挤的空间。然后,我尝试在实例化facetGrid对象时使用margin_titles = True选项。但是在这种情况下,行变量标签位于图例右侧外侧,可能离图表太离谱。要显示

  1. 移动图例内缘冠军时,margin_titles = Truelegend_out=True
  2. 允许行变量标签:

    所以可以简单的方法来改善我的两个美分值得思考的审美在y轴标签的左边。

  3. 其他想法?

对不起,没有积累足够的分数可以添加图表示例。

回答

2

当然可以!枚举在轴上似乎工作得很好。

import seaborn as sns 
import matplotlib.pyplot as plt 
sns.set(style='ticks', color_codes=True) 

tips = sns.load_dataset('tips') 

g = sns.FacetGrid(tips, col='time', row='sex') 
g = g.map(plt.scatter, 'total_bill', 'tip', edgecolor='w') 

for i, axes_row in enumerate(g.axes): 
    for j, axes_col in enumerate(axes_row): 
     row, col = axes_col.get_title().split('|') 

     if i == 0: 
      axes_col.set_title(col.strip()) 
     else: 
      axes_col.set_title('') 

     if j == 0: 
      ylabel = axes_col.get_ylabel() 
      axes_col.set_ylabel(row.strip() + ' | ' + ylabel) 

plt.show() 

enter image description here

相关问题