在matplotlib的轴中设置轴标签

时间:2018-08-30 16:01:54

标签: python matplotlib seaborn

我正在尝试以下代码绘制一些图形:

fig = plt.figure(figsize=(10, 20))
for idx, col in enumerate(['Pclass', 'Sex']):
    ax = fig.add_subplot(2, 1, idx+1)
    _ = ax.set(ylabel='Counts')
    _ = sns.countplot(x=col, hue='Survived', data=full, ax=ax)

我得到的输出是: Link to the graphs here

您会看到y标签被设置为seaborn countplot默认标签'count',但是我想将其更改为'Counts'。我已经尝试过axes方法set_ylabel并设置了ylabel参数,但是图形没有变化。我在做什么错了?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方法,在绘制后更改ylabel

fig = plt.figure(figsize=(10, 20))
for idx, col in enumerate(['Pclass', 'Sex']):
    ax = fig.add_subplot(2, 1, idx+1)
    sns.countplot(x=col, hue='Survived', data=full, ax=ax)
    ax.set_ylabel('Counts')
相关问题