Plotting offset errorbars with pyplot.errorbar()

We use errorbar() to show the expected range of a probability distribution with an associated observed quantity. Sometimes, the observed quantity falls outside this expected range, which we were able to plot by specifying negative xerr values. An example of this can be seen here.

After reading this issue and the documentation, it seems this is not the intended use-case for errorbar. I have a couple of questions. First is purely out of curiosity, was there any reason other than the < 3.6.0 documentation suggesting that xerr and yerr should be positive values that it was changed? And second, what is best way to recreate this image without essentially rewriting the errorbar function to plot the lines and caps independent of the scatter plot. Possible follow up, if the only reason is to be consistent with the documentation, would you accept a PR from me to revert this change and update the documentation accordingly?

1 Like

Having the same issue

Interesting. Sorry for not seeing this sooner. This is another example of our users being very clever and finding off-label uses for things!

Given the two issues we had there are some people who are confused by the behavior with negative error bars and supporting it is contrary to the documentation.

I also think that at a conceptual level, negative error bars are a bit fishy as they are, as the API is set up, a delta around the value (they go from y - lower to y + upper). In your case @wsavran I assume that you are doing something to convert absolute ranges to be relative to the observed value. While this works, it seems a bit contrary to the intent.

As to how to re-create it, I would split it into two calls: one to errorbar (with the average of half width of the expected range as the value) without a marker and one to plot (or scatter) for the actual observations. It is an extra line (and depending on what you pass into where maybe an annoying change) but I think it is clearer as to the intent.

I could probably be convinced to change the exception to a warning, but it would need to be a very compelling argument.