【问题标题】:rotate ylabel in seaborn pairplot在seaborn pairplot中旋转ylabel
【发布时间】:2020-05-21 13:50:24
【问题描述】:

我有这张桌子:

 Wow   Bob  Class  Cook shlook    ban
 1   2.5      0     0      d   44.0
 3   7.5      0     1      f   55.0
 5  12.5      0     0      g   56.0
 4  10.0      0     1      c    3.0
 6  15.0      0     0    esd  323.0
..  ...   ...    ...   ...    ...    ...
 2  14.0      2     1      f    NaN
 2  15.0      2     1      d    2.0
 2  16.0      2     0      d    2.0
 2  17.0      2     0      f    2.0
 2  18.0      2     1      g    NaN

我一直在尝试绘制 seaborn.pairblot 并使用此代码将 ylables(不是刻度)点为 90 度:

for axes in g.axes.flat:
     axes.set_ylabel(axes.get_ylabel(), rotation=90, horizontalalignment='left')
plt.show()

这是我得到的情节:

如您所见,标签没有旋转。 我该怎么办?

谢谢!

【问题讨论】:

  • 什么是g?将创建 g 的代码添加到您的问题中。另外,你试过rotation=0吗?
  • g = sns.pairplot(df)
  • 谢谢!它奏效了,但现在标签离地块太近了:(

标签: python matplotlib data-visualization seaborn


【解决方案1】:

将旋转设置为 0,将 ha 设置为“右”:

sns.set()
tips = sns.load_dataset("tips")
#fig, ax = plt.subplots(1, 2,figsize=(10,4))

g = sns.pairplot(tips)
for axes in g.axes.flat:
     axes.set_ylabel(axes.get_ylabel(), rotation=0, horizontalalignment='right')
plt.show()

一个有用的检查地方是matplotlib vignette,:

您可以使用对齐参数水平对齐来布置文本, 垂直对齐和多对齐。水平对齐控件 文本的 x 位置参数是否指示左侧, 文本边界框的中心或右侧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 2019-07-13
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多