当使用 Seaborn facetGrid 图时。是否可以将行变量标签设置在左侧(例如,作为两行子图 y 轴标签的第一行)?
作为子图标题的一部分,默认位置在顶部。不幸的是,合并的文本有时会变得太长而无法合理地放入那个拥挤的空间。然后我尝试在实例化 facetGrid 对象时使用 margin_titles = True 选项。但在这种情况下,行变量标签位于图例右侧的外侧,这可能离图表太远了。
因此,在我的两分钱思想中,提高美感的可能简单方法:
- 当
margin_titles = True
和legend_out=True
时,将边距标题移动到图例中 - 允许行变量标签显示在 y 轴标签之前的左侧。
- 其他想法?
抱歉,积分不够,无法添加图表示例。
最佳答案
没问题!在轴上枚举似乎工作得很好。
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()
关于Python seaborn facetGrid : Is it possible to set row category label location to the left,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26134082/