旋转seaborn barplot的刻度标签 [英] Rotate tick labels for seaborn barplot

查看:57
本文介绍了旋转seaborn barplot的刻度标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示带有旋转 x 轴标签的图表,但该图表未显示.

I am trying to display a chart with rotated x-axis labels, but the chart is not displaying.

import seaborn as sns
%matplotlib inline

yellow='#FFB11E'
by_school=sns.barplot(x ='Organization Name',y ='Score',data = combined.sort('Organization Name'),color=yellow,ci=None)

这时我可以看到图像,但是在设置xticklabel之后,我不再仅看到对象引用了.(我会发布图片,但是我信誉不高:()

At this point I can see the image, but after I set the xticklabel, I don't see the image anymore only an object reference. (I would post the image, but I don't enough reputation :()

by_school.set_xticklabels('Organization Name',rotation=45)

<matplotlib.axes._subplots.AxesSubplot at 0x3971a6a0>

这里发布了一个类似的问题:在 seaborn factorplot 中旋转标签文本但解决方案不起作用.

A similar question is posted here: Rotate label text in seaborn factorplot but the solution is not working.

推荐答案

对于每个 ticklable,您需要一个不同的方法调用,即 .set_rotation.由于您已经有了ticklabel,因此只需更改其轮换即可:

You need a different method call, namely .set_rotation for each ticklables. Since you already have the ticklabels, just change their rotations:

for item in by_school.get_xticklabels():
    item.set_rotation(45)

barplot 返回一个 matplotlib.axes 对象(从 seaborn 0.6.0 开始),因此您必须以这种方式旋转标签.在其他情况下,当方法返回一个 FacetGrid 对象时,请参考 在seaborn factorplot中旋转标签文本

barplot returns a matplotlib.axes object (as of seaborn 0.6.0), therefore you have to rotate the labels this way. In other cases, when the method returns a FacetGrid object, refer to Rotate label text in seaborn factorplot

这篇关于旋转seaborn barplot的刻度标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆