Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Problem
The name of the errorbar() function suggests that it is specifically for adding error bars to a plot. However, it's actually much more general than that, giving a very convenient way to add additional data to a plot. For example, I've been using it to denote 25% and 75% percentiles when plotting means. The problem is that this more general usage is precluded because in such use cases, the error bars can be negative, and recent versions throw an error in this case.
Proposed solution
My proposed solution is to get rid of this test. Users can easily see if their error bars bound the function they're plotting, and may very well, for reasons as noted above, want to use the functionality in cases where the error bars are not positive.
Accepting negative error bars was the behavior of errorbar() up until commit #2cd1846751, which throws an error if the error bars are not positive. Later changes refined this to throw an error for negative error bars. I believe this test was incorporated into version 2.6.
My enhancement request is for this test to be removed. The patch would be:
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.pyindex b42d526701..f92c6e785d 100644--- a/lib/matplotlib/axes/_axes.py+++ b/lib/matplotlib/axes/_axes.py@@ -3474,8 +3474,6 @@ class Axes(_AxesBase): errors. - *None*: No errorbar. - All values must be >= 0.- See :doc:`/gallery/statistics/errorbar_features` for an example on the usage of ``xerr`` and ``yerr``. @@ -3744,10 +3742,6 @@ class Axes(_AxesBase): "Use NaN if you want to skip a value.") res = np.zeros(err.shape, dtype=bool) # Default in case of nan- if np.any(np.less(err, -err, out=res, where=(err == err))):- # like err<0, but also works for timedelta and nan.- raise ValueError(- f"'{dep_axis}err' must not contain negative values") # This is like # elow, ehigh = np.broadcast_to(...) # return dep - elow * ~lolims, dep + ehigh * ~uplims