如何在Seaborn PairGrid中对齐y标签

时间:2016-10-10 14:56:42

标签: python matplotlib seaborn

取自documentation

>>> import matplotlib.pyplot as plt
>>> import seaborn as sns; sns.set()
>>> iris = sns.load_dataset("iris")
>>> g = sns.PairGrid(iris)
>>> g = g.map(plt.scatter)

PairGrid

如何对齐y标签?

我尝试了什么:

for ax in g.axes.flat:
    ax.yaxis.labelpad = 20

但是,只有将所有标签移动指定数量而不是对齐它们。

2 个答案:

答案 0 :(得分:3)

是的,那种对齐很糟糕。怎么敢让自己制作"attractive statistical graphics"的包裹在标签对齐方面如此糟糕?开玩笑,我爱我一些海藻,至少是为了如何改善我自己的情节。

您正在寻找:

ax.get_yaxis().set_label_coords(x,y) # conveniently in axis coordinates

另外,我只会遍历显示标签的轴,但这只是我:

for ax in g.axes[:,0]:
    ax.get_yaxis().set_label_coords(-0.2,0.5)

0.5用于居中的垂直对齐,-0.2用于向左略微偏移(试错)。

enter image description here

答案 1 :(得分:0)

如果遍历所有轴 g.axes.flatten() 对我有用。

for ax in g.axes.flatten():
    ax.get_yaxis().set_label_coords(-0.2,0.5)
相关问题