seaborn
seaborn copied to clipboard
Error bars in barplot do not respect clip_on
Hello! It seems that error bars do not have clearly defined clipping behavior within barplots.
Expected behavior: Setting clip_on=True should result in neither bars or error bars being clipped.
Actual behavior: When setting clip_on to be True, bars in the bar plots are (correctly) not clipped at plot borders. However, errorbars are clipped.
Platform: Seaborn: 0.9.0 (though also appears to be the case in 0.10.1), Linux (*buntu), Python: 3.6.8, Matplotlib: 3.0.2
Here is a MWE:
import pandas
import seaborn as sns
import matplotlib.pyplot as plt
mdf = pandas.DataFrame({"a": [5, 8, 9, 10, 1, 2, 3, 4], "b": [0, 0, 0, 0, 1, 1, 1, 1]})
sns.barplot(data=mdf, x="b", y="a", clip_on=False)
plt.gca().set_ylim(0, 7.5)
plt.tight_layout(rect=[0, 0, 1, .5])
plt.show()
Thanks!
Expected behavior: Setting clip_on=True should result in neither bars or error bars being clipped.
It's reasonable to have this expectation, but it's not correct. The kwargs (as the docs say) are passed through to ax.bar only. But you could do e.g.
ax = sns.barplot(data=mdf, x="b", y="a", clip_on=False)
ax.set_ylim(0, 7.5)
plt.setp(ax.lines, clip_on=False)
plt.tight_layout(rect=[0, 0, 1, .5])
Expected behavior: Setting clip_on=True should result in neither bars or error bars being clipped.
It's reasonable to have this expectation, but it's not correct. The kwargs (as the docs say) are passed through to
ax.baronly. But you could do e.g.ax = sns.barplot(data=mdf, x="b", y="a", clip_on=False) ax.set_ylim(0, 7.5) plt.setp(ax.lines, clip_on=False) plt.tight_layout(rect=[0, 0, 1, .5])
Sorry not understanding, as clip_on is a kwarg for matplotlib.axes.Axes.bar() and you docs seem to explicitly imply that it would be passed to it.
Perhaps you could quote the relevant part of the docs? Otherwise it’s impossible to fix…
Perhaps you could quote the relevant part of the docs? Otherwise it’s impossible to fix…
kwargs: key, value mappings
Other keyword arguments are passed through to matplotlib.axes.Axes.bar().
Sorry forgot to put link https://seaborn.pydata.org/generated/seaborn.barplot.html
Yes, it is true that other kwargs are passed through to ax.bar. If the bar itself extended past the axis limits, it would be visible. But the error bars are drawn using ax.plot.
In v0.13+, barplot has an err_kws that can be used here:
ax = sns.barplot(tips, x="day", y="total_bill", errorbar="sd", err_kws=dict(clip_on=False))
ax.set(ylim=(0, 25))