问题
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