Aesthetics of barplot bars and error bars in seaborn

喜欢而已 提交于 2019-12-24 14:40:32

问题


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.

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))

I've tried:

g.errorbar(capthick=2)

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.


回答1:


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))


来源:https://stackoverflow.com/questions/28050953/aesthetics-of-barplot-bars-and-error-bars-in-seaborn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!