Seaborn的barplot bar和error bar的美学 [英] Aesthetics of barplot bars and error bars in seaborn
问题描述
我正在使用seaborn库来可视化数据,并且我想更改有关输出图的某些内容以供发布.我希望误差条更窄,有大写字母,我希望所有误差条周围的边框都是黑色的.
I'm using the seaborn library to visualize data and I want to change some things about the output graphs for publication. I want the error bars to be more narrow, with caps, and I'd like the border around all of the bars to be black.
我想象有某种方法可以使用pyplot(或sns.set_context中的rc词典)更改绘图,但是我不知道该怎么做.
I imagine that there is some way to change the plot using pyplot (or perhaps the rc dictionary in sns.set_context), but I can't figure out how to do this.
colors = ["black", "grey", "white"]
g = sns.barplot("TYPEMOD", "SCORE", ci=68, data=final_data, palette=sns.xkcd_palette(colors))
我尝试过:
g.errorbar(capthick=2)
但这会产生错误,因为需要我忽略sns.barplot中的错误栏(这些错误栏是通过设置ci参数生成的,因此我将ci = None设置为零,然后执行全新的错误带有g.errorbar的条).我觉得必须有某种方法可以完成所有这些工作,因为这似乎是一个很小的更改,但是我无法在任何常规文档中找到任何内容.
But that gives an error, because requires me to just ignore the error bars in sns.barplot (which are generated by setting the ci parameter, so I'd set ci=None, and then I'd do completely new error bars with g.errorbar). I feel like there must be some way to do this without all of this effort, since it seems like a minor change, but I can't find anything in the seaborn documentation.
我还想将我的情节图中所有条周围的边框更改为黑色.
I'd also like to change the border around all of the bars in my barplot to be black.
推荐答案
barplot
不是在内部使用errorbar
,它只是在CI的间隔内画线,因此无法添加上限.误差线宽度本身只是lines.linewidth
rc参数的比例因子,因此您可以临时设置它来控制它:
barplot
isn't using errorbar
under the hood, it's just drawing lines in the interval of the CI, so there's no way to add caps. The errorbar width itself is just a scaled factor of the lines.linewidth
rc parameter, so you can set that temporarily to control it:
with mpl.rc_context("lines.linewidth": 1}):
colors = ["black", "grey", "white"]
g = sns.barplot("TYPEMOD", "SCORE", ci=68, data=final_data,
palette=sns.xkcd_palette(colors))
这篇关于Seaborn的barplot bar和error bar的美学的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!