2017-07-06 346 views
2

我有一个问题与2014年的问题基本相同(请参阅here)。但是,我的脚本仍然会报错。在seaborn boxplot中旋转xtick标签?

以下是我的工作:我有一个有几列的熊猫数据框。我绘制了一个简单的boxplot比较。

g = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) 
g.set_xticklabels(rotation=30) 

图表看起来是这样的:

enter image description here

我想用30度旋转x标签。因此我使用g.set_xticklabels(rotation=30)。不过,我得到以下错误:

set_xticklabels() missing 1 required positional argument: 'labels'

我不知道如何通过matplotliblabels参数seaborns sns.boxplot。有任何想法吗?

回答

8

您链接到的问题使用factorplot。一个因素图返回它自己的类,它有一个名为set_xticklabels(rotation)的方法。这与matplotlib Axesset_xticklabels方法不同。

在链接的问题的答案也有,你可以使用

ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) 
ax.set_xticklabels(ax.get_xticklabels(),rotation=30) 

ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) 
plt.setp(ax.get_xticklabels(), rotation=45) 
其他选项