Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Errorbar: do not ignore inf but plot errorbar bigger than current frame size #7876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FrederikLauber opened this issue Jan 19, 2017 · 14 comments
Labels
API: changes Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

Comments

@FrederikLauber
Copy link

FrederikLauber commented Jan 19, 2017

Hi,

if you run this code:

import numpy
import matplotlib.pyplot as plt
fig1, ax1 = plt.subplots(figsize=(15, 9))
a = numpy.arange(10)
b = a**2
c = numpy.array([1.0] * 10)
c[2] = numpy.nan
c[8] = numpy.inf
ax1.errorbar(a,b,c)
fig1.show()

you will get this figure:

figure_1

As you can see, both the error bar at 3 and 9 are missing. 3 has an error of "nan", so leaving out the error bar to indicate this is fine in my eyes. 9 has "inf" and also has no error bar. I think it would be better, if this error bar would be bigger then the frame of the figure.
Hence you would see that the error is at this point is bigger then the current y limits and not confuse this with a non existent error. Also in plots with vastly different error bars, an infinite error can no longer be confused with an error of size 0.

Thanks in advance,

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Jan 19, 2017
@tacaswell tacaswell added new-contributor-friendly Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues API: changes and removed new-contributor-friendly labels Jan 19, 2017
@tacaswell
Copy link
Member

http://matplotlib.org/examples/statistics/errorbar_limits.html is another way this can be dealt with which requires a bit more user input to interpret what and 'infinite' errorbar means.

It might be possible to automatically do something like that in the case of inf.

I think another reasonable approach to the error being inf is to drop the point altogether (likely making too many assumptions to be in mpl) as if the error is infinite, then the number is effectively meaningless.

@FrederikLauber
Copy link
Author

Thanks for the link but it does not really help in my situation.
maybe some more context.
At the moment I want to plot a histogram (I am actually binning the data myself and then use errorbar to plot it) with error bars. The problem arises if you have a bin with a single entry.
With that, the std becomes infinite. At the moment, I cannot make a difference between the bins which have a finite and very small error and bins which basically have no information at all. They are displayed the same which is really really irritating.

If instead inf errors would fill the complete direction (but not count towards the limits), I would show this difference. Also, if I prefer to not have this range filling error bar, I can just replace infs with nans and have the old back.

@efiring
Copy link
Member

efiring commented Jan 23, 2017 via email

@FrederikLauber
Copy link
Author

Hi,

well, its math, if you have a Bessel correction in your error formular( i.e. 1/(N-1)) the error will always become infinite for singular events which makes total sense. A singular measurement does usually tell you nothing which is indicated by a infinite error on the value (you get the same for a fit through a singular data point, the parameters will be random with an infinite error). If you pick a different error formular, you might not get to inf but most error formuars I know contain a Bessel correction due to being an estimator to the actual error because the actual error is normally not known.

Either way, its not matplotlib which should decide to drop this from my plotting but me. And displaying an error bigger then the frame will 1. indicate to the user what is going on at the data point, if he does not like it, he can either revert to the nan behaviour very easily or choose some other way to reflect this) 2. does not get confused with an nonexistent or close to 0 error bar.

@story645
Copy link
Member

story645 commented Jan 23, 2017

While I agree with @efiring that infinite error doesn't make sense, I agree with @FrederikLauber on deferring to the user. I support the idea of just extending a line to the axis extent as that technically won't change the API. inf yerr would be plotting infinite lines relative to the (x,y) point. I'm not sure, but it may also be sorta consistent with the idea of #5253 that sometimes lines are supposed to just extend.

Maybe matplotlib should raise a warning as to that being what it's doing, but that might be clutter...

@efiring
Copy link
Member

efiring commented Jan 23, 2017 via email

@zmbc
Copy link

zmbc commented May 4, 2022

I am running into this issue in the context of a forest-plot-style comparison of median estimates from survival regressions. I am using the (2,N) shaped form of xerr. Frequently in survival regression, e.g. a Kaplan-Meier estimator, the lower bound of the median and the point estimate of the median are both well-defined, but the upper bound is not. I wish there were some way to have the error in that direction continue to the edge of the frame.

@tacaswell
Copy link
Member

@zmbc You should look at the lolims and uplims keyword arguements https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.errorbar.html#matplotlib-axes-axes-errorbar which exist for the purpose of indicating that only one of the bounds should be trusted.

@jklymak
Copy link
Member

jklymak commented May 4, 2022

Yes, I vote that this be closed...

@zmbc
Copy link

zmbc commented May 4, 2022

@tacaswell I did, and unless I'm missing something lolims and uplims can't do what I want. As you can see in this example, using lolims or uplims to give one error direction an arrow necessarily removes the error in the other direction. In my use case, there is a well-defined lower bound, which I want to display, and also an upper bound that is unknown.

@efiring
Copy link
Member

efiring commented May 4, 2022

Can you get the desired effect by substituting a very large number for the inf and then manually set the desired ylim for the plot?

@tacaswell
Copy link
Member

@zmbc 🐑 Sorry, I answered too quickly and was mistaken about exactly what that API did (I remembered the arrow up/down, but not that it dropped the other side).

I am inclined to re-open this (or open a new issue) to track the request from "real error in one direction, line with arrow in the other".

I am not sure that "off the screen" is the right thing for us to ever do by default because that suggest that there might be a real value out there if you changed the limits right (and I do not recall off the top of my head if auto-limits take in to account error bars...I hope they do). I think the right thing is something like |----O----> (with a real error to the left and a "goes that way" error to the right).

@zmbc
Copy link

zmbc commented May 5, 2022

Good idea @efiring, I will do that for now.

I agree that the arrow would be preferable to an infinitely-extending line.

@jklymak
Copy link
Member

jklymak commented May 5, 2022

I opened #22980 to track the idea of using an arrow...

@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: changes Difficulty: Medium https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Projects
None yet
Development

No branches or pull requests

6 participants