9

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

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

因此,在我的两美分思想中,改善审美的可能简单方法:

  1. margin_titles = True在和时移动图例内的边距标题legend_out=True
  2. 允许行变量标签显示在 y 轴标签之前的左侧。
  3. 其他想法?

抱歉,积分不足,无法添加图表示例。

4

1 回答 1

3

确定的事!枚举轴似乎工作得很好。

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()

在此处输入图像描述

于 2016-05-29T09:28:01.173 回答