在seaborn pairplot中旋转标签

2024-09-28 19:10:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这张桌子:

 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(而不是ticks)点成90度:

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

这是我得到的情节: enter image description here

如您所见,标签不会旋转。 我该怎么办

谢谢大家!


Tags: 代码绘制seabornnanclassbob桌子cook
1条回答
网友
1楼 · 发布于 2024-09-28 19:10:42

将旋转设置为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()

enter image description here

检查matplotlibvignette是一个有用的地方:

You can lay out text with the alignment arguments horizontalalignment, verticalalignment, and multialignment. horizontalalignment controls whether the x positional argument for the text indicates the left, center or right side of the text bounding box.

enter image description here

相关问题 更多 >