旋转轴标签

Eer*_*ist 3 python matplotlib subplot axis-labels seaborn

我有一个看起来像这样的图(这是著名的 Wine 数据集):

在此输入图像描述

正如您所看到的,x 轴标签重叠,因此我需要旋转。

注意!我对旋转 x 刻度不感兴趣(如此处所述,但对标签文本(即alcoholmalic_acid等)感兴趣。

创建绘图的逻辑如下:我使用 创建一个网格axd = fig.subplot_mosaic(...),然后为底部绘图设置标签axd[...].set_xlabel("something")set_xlabel如果能接受一个参数那就太好了rotation,但不幸的是事实并非如此。

小智 5

根据文档 set_xlabel接受文本参数,其中rotation之一。

不过,我用来测试这一点的示例如下所示。

import matplotlib.pyplot as plt
import numpy as np

plt.plot()
plt.gca().set_xlabel('Test', rotation='vertical')
Run Code Online (Sandbox Code Playgroud)