【发布时间】:2017-08-06 10:15:02
【问题描述】:
我正在使用 Seaborn 使用 pandas 数据框中的数据制作箱线图。
colorpalette = sns.hls_palette(8,h=.9)
g = sns.boxplot(x="estimator", y="mean_score", data=dFrame, palette=colorpalette)
g.set(ylabel='Mean Accuracy', xlabel='')
plt.show()
这导致我在上图中。如您所见,刻度标签太长而不能排成一行。因此,我计划在 xticklabels 上使用 textwrap 将它们跨越多行。为了获得标签,我尝试使用
g.xaxis.get_ticklabels()
返回以下内容
<a list of 9 Text major ticklabel objects>
如果我像这样循环尝试
for item in g.xaxis.get_ticklabels():
print(item)
我得到以下输出
Text(0,0,'ExtraTreesClassifier')
Text(1,0,'RandomForestClassifier')
Text(2,0,'GradientBoostingClassifier')
Text(3,0,'LogisticRegression')
Text(4,0,'DecisionTreeClassifier')
Text(5,0,'kNearestNeighbors')
Text(6,0,'LinearSVC')
Text(7,0,'Perceptron')
有没有办法使用 seaborn 中的默认函数/方法更有效地做到这一点。
【问题讨论】:
标签: python matplotlib seaborn