Python seaborn facetGrid : Is it possible to set row category label location to the left

标签 python matplotlib label margin seaborn

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

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

因此,在我的两分钱思想中,提高美感的可能简单方法:

  1. margin_titles = Truelegend_out=True 时,将边距标题移动到图例中
  2. 允许行变量标签显示在 y 轴标签之前的左侧。
  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()

enter image description here

关于Python seaborn facetGrid : Is it possible to set row category label location to the left,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26134082/

相关文章:

python - 标记外部节点,与networkx中的其他节点/边缘重叠最小

python - 线程错误 : AttributeError: 'NoneType' object has no attribute '_initialized'

python - requests.json 和 json.loads() JSONDecodeError : Expecting value: line 1 column 1 (char 0)

python-2.7 - 如何在 Matplotlib (Numpy) 中生成 MATLAB 图(插值)?

javascript - 可缩放的冰柱 d3 在图表中添加标签

java - java反编译输出中的标签位置

python - 3D 体积的时间序列插值(MATLAB 或 Python)

python - 使用 SVD 进行降维,指定要保持的能量

python - 散点图点重叠轴

Python-实时传感器数据绘图