Skip to content
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

[Bug]: Errorbars separated from markers with negative errors #21101

Closed
nbrunett opened this issue Sep 16, 2021 · 2 comments · Fixed by #21266
Closed

[Bug]: Errorbars separated from markers with negative errors #21101

nbrunett opened this issue Sep 16, 2021 · 2 comments · Fixed by #21266
Labels
Good first issue Open a pull request against these issues if there are no active ones!
Milestone

Comments

@nbrunett
Copy link
Contributor

Bug summary

If unique upper and lower errors are specified, and one of them is negative, then the errorbar will appear separate from the marker. It looks like this was mentioned ages ago in #2717 but I could not find a follow up to that issue.

Code for reproduction

import matplotlib.pyplot as plt

# 1
plt.errorbar([0], [0], yerr=[[-0.5], [1]], marker="o")

# 2
plt.errorbar([0], [0], xerr=[[-0.5], [1]], marker="o")

# 3
plt.errorbar([0], [0], xerr=[[-0.5], [1]], yerr=[[-0.5], [1]], marker="o")

Actual outcome

1

image

2

image

3

image

Expected outcome

I understand the documentation states that the error inputs should be positive values, but I would expect some error like ValueError when there is a negative value provided, rather than it trying to make the plot. I would prefer an error being thrown and the plot not being made.

Operating system

CentOS Linux release 7.9.2009 (Core)

Matplotlib Version

3.4.3

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.9.6

Jupyter version

3.1.9

Other libraries

No response

Installation

conda

Conda channel

No response

@tacaswell
Copy link
Member

So I see why it is doing this ('we draw the error bar from (val - lower_error, val + upper_error)), but I agree, if we document that negative errors should not work, we should do the validation and raise ValueError

The tasks here are:

  • add validator to at at least the errorbar method
  • investigate how much work it would be to add validation to updating the errorbars after-the-fact (I think in that case the user has to do the offsets them selves so there may be nothing we can do)
  • add a test

@tacaswell tacaswell added the Good first issue Open a pull request against these issues if there are no active ones! label Sep 17, 2021
@tacaswell tacaswell added this to the v3.6.0 milestone Sep 17, 2021
@lucafs
Copy link

lucafs commented Sep 23, 2021

I will try to work on this near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants