Skip to content

Errorbar semilogy switch to log y removed error bars when crosses into negative #9149

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
PaulKuin opened this issue Sep 1, 2017 · 3 comments
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action

Comments

@PaulKuin
Copy link

PaulKuin commented Sep 1, 2017

Bug report

Bug summary

When plotting error bars on data points, where the data is positive but the bar with the data-error is entering negative values, switching to log Y axes using semilogy() means that some data points are plotted without error bars at all (both y-err bars disappear).

Code for reproduction

create a file example.dat:
x dx y dy
1.046850 0.0029168 0.042551 0.02420
1.506679 0.0030152 0.027573 0.02252
3.028597 0.1959554 0.021218 0.00974
3.656348 0.1034119 0.002788 0.01059
4.949535 0.4693247 0.006276 0.00969

from astropy.io import ascii
from pylab import figure, errorbar,semilogy
t = ascii.read('example.dat')
figure()
errorbar(t['x'],t['y'],xerr=t['dx'],yerr=t['dy'],fmt='s')

This shows a linear plot with errorbars fine. The third data point error bar extends into negative territory.

semilogy()

Now the plot has a log y axis, but the error bar of the third point is gone.

# Paste your code here
#
#

from astropy.io import ascii
from pylab import figure, errorbar,semilogy
t = ascii.read('example.dat')
figure()
errorbar(t['x'],t['y'],xerr=t['dx'],yerr=t['dy'],fmt='s')

#This shows a linear plot with errorbars fine. The third data point error bar extends into negative territory.

semilogy()

#Now the plot has a log y axis, but the error bar of the third point is gone.
Actual outcome

screen shot 2017-09-01 at 15 43 50

screen shot 2017-09-01 at 15 44 05

# If applicable, paste the console output here
#
#

Expected outcome

An errorbar in the log plot, surely the positive bar, and the negative going a few (3 or 5) decades down (perhaps with an arrow ending).

Matplotlib version

  • Operating System: OSX
  • Matplotlib Version: 2.0.2
  • Python Version:2.7
  • Jupyter Version (if applicable):
  • Other Libraries: astropy

anaconda astroconda

@dstansby
Copy link
Member

dstansby commented Sep 1, 2017

Yeah, we change the behaviour of this recently to fix some other issues (#8836). There is a note in the docstring of errorbar that what you're describing is expected behaviour, but I do agree that we should find some way to put the errorbars back in and have them go right down.

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Sep 1, 2017
@tacaswell
Copy link
Member

I think the issue here is that exactly what should be done with the negative is not clear, I think there are at least 4 options:

  • mask the bottom point and drop the whole errorbar (it is implemented as a single line)
  • mask the bottom point, but still draw the top half (not done, but would be possible without too much trouble)
  • clip to some 'small' number (now picking that small number is it's own issue and now we have to be careful on auto-scaling to not include that in the limits) (and this is implemented via a kwarg flag)
    • should we clip to 0+epsilon or val * epsilon? (I think we go with the first option now, but would have to check the code)
  • replace the bottom one with an arrow, but this also has to be clipped so the difference is still positive so we have to pick that number

See https://matplotlib.org/examples/statistics/errorbar_limits.html for all the ways to have finer grain control over how limits are drawn (if you want to use log then negative values are probably non-physical and you really just have no lower bound for the value (ex neutrino mass)) so it might be worth doing the extra work to identify that.

Also see https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_yscale.html , if you use ax.set_yscale('log', nonposy='clip') it should clip the error bars to some very small number.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 17, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2023
@rcomer rcomer added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. status: inactive Marked by the “Stale” Github Action
Projects
None yet
Development

No branches or pull requests

4 participants