简体   繁体   中英

Aesthetics of barplot bars and error bars in 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM