question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error bars in barplot do not respect clip_on

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Jun 18, 2020

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])
0reactions
mwaskomcommented, Mar 2, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Barplot with error bars - The R Graph Gallery
Error bars give a general idea of how precise a measurement is, or conversely, how far from the reported value the true (error...
Read more >
The issue with error bars - From data to Viz
Error bars give a general idea of how precise a measurement is, or conversely, how far from the reported value the true (error...
Read more >
Turn off error bars in Seaborn Bar Plot - Stack Overflow
I'm using GridSpec in matplotlib to create a page that has 9 subplots. One of the subplots is a ...
Read more >
Adding error bars to a grouped bar plot - MATLAB Answers
Hi! I'm trying to plot a grouped bar graph with standard errors, and have managed this so far, which almost works but the...
Read more >
Adding error bars to a simple bar plot
The easy solution to finding the bar centers is in the barplot() command itself: in addition to plotting the graph, the function also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found