【问题标题】:Python seaborn facetGrid: Is it possible to set row category label location to the leftPython seaborn facetGrid:是否可以将行类别标签位置设置在左侧
【发布时间】:2014-11-25 20:43:46
【问题描述】:
使用 Seaborn facetGrid 绘图时。是否可以将行变量标签设置在左侧(例如,作为两行子图 y 轴标签的第一行)?
默认位置位于顶部,作为子图标题的一部分。不幸的是,合并后的文本有时会变得太长,无法合法地融入那个拥挤的空间。然后我在实例化 facetGrid 对象时尝试使用 margin_titles = True 选项。但在这种情况下,行变量标签位于图例右侧的外侧,离图表太远会很尴尬。
所以在我的两分钱的想法中,改善审美的可能的简单方法:
-
margin_titles = True 和legend_out=True 时移动图例内的边距标题
- 允许行变量标签显示在左侧 y 轴标签之前。
- 其他想法?
抱歉,积分不够,无法添加图表示例。
【问题讨论】:
标签:
python
matplotlib
label
margin
seaborn
【解决方案1】:
当然!枚举轴似乎工作得很好。
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()