use*_*545 8 python label margin matplotlib seaborn
使用Seaborn facetGrid图时.是否可以将行变量标签设置为左侧(例如,作为两行子图y轴标签的第一行)?
默认位置位于顶部,作为子图标题的一部分.不幸的是,合并后的文字有时会变得太长而无法合法地融入那个拥挤的空间.然后我尝试在实例化facetGrid对象时使用margin_titles = True选项.但在这种情况下,行变量标签位于图例右侧的外部,这可能与图表的距离太远.
因此,在我2美分的思想中,可能的简单方法可以改善美学:
margin_titles = True和时,在图例中移动边距标题legend_out=True 抱歉,没有积累足够的积分来添加图表示例.
当然可以!枚举轴似乎工作得很好。
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()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1659 次 |
| 最近记录: |