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

Skip to content

[Bug]: Incorrect error bar on log scale #21579

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
fnareoh opened this issue Nov 10, 2021 · 2 comments
Closed

[Bug]: Incorrect error bar on log scale #21579

fnareoh opened this issue Nov 10, 2021 · 2 comments
Labels
Community support Users in need of help.

Comments

@fnareoh
Copy link

fnareoh commented Nov 10, 2021

Bug summary

Thank you for the amazing work!

The issue is different from #163, the behavior is that if you try to plot a zero point (without any error) on a logscale (y) graph the error bar of the previous point is not plotting correctly, see the example where mini0 error bar is incorrect (desired behavior in mini1):
https://imgur.com/a/lP75nwU

Code for reproduction

import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.axes()
ax.set_yscale("log")

ys =[7, 0]
ys2 =[1, 1]
errs =[5, 0]
xs = [0, 1]
ax.errorbar(xs, ys,fmt="o-", yerr=errs)
ax.errorbar(xs, ys2,fmt="o-")
fig.savefig('mini0.png')
fig.clear()
ax = plt.axes()
ax.set_yscale("log")
ys =[7, 1]
ax.errorbar(xs, ys,fmt="o-", yerr=errs)
ax.errorbar(xs, ys2,fmt="o-")
fig.savefig('mini1.png')

Actual outcome

mini0

mini1

Expected outcome

I expected the errorbar in mini0 for the first point to be as in mini1, not going to 0. As in my use case not plotting the point at 0 in logscale made sense I didn't expected it to impact the previous point error bar.

Operating system

No response

Matplotlib Version

3.4.3

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Other libraries

No response

Installation

No response

Conda channel

No response

@jklymak
Copy link
Member

jklymak commented Nov 10, 2021

First I found this slightly easier to see what is going on:

import matplotlib.pyplot as plt

fig, axs = plt.subplots(1, 2)

for nn, ax in enumerate(axs):

    if nn==0:
        ys = [7, 7, 0]
    else:
        ys = [7, 7, 0.00001]
    errs = 5
    xs = [0, 1, 2]
    ax.errorbar(xs, ys, fmt="o-", yerr=errs, ecolor='C1')
    ax.set_ylim([1e-4, 30])
    ax.set_yscale("log")
plt.show()

This gives:

Figure_1

So note that errorbar tries to draw the connecting line down to 1e-81 or whatever it sets the zero to, and the blue line down to 1e-81 covers the actual error bar...

Note that you get the same behaviour from

fig, ax = plt.subplots()
ax.semilogy([0, 1, 2], [7, 7, 0])
ax.set_ylim([1e-4, 30])
plt.show()

So I'm not sure we will change this anytime soon. I'm not sure there is an action item here...

@jklymak jklymak added the Community support Users in need of help. label Nov 10, 2021
@fnareoh
Copy link
Author

fnareoh commented Nov 10, 2021

Hum ok I see, I would have never suspected this and didn't see anybody with the same issue! Thank you very much for the clarification!

@fnareoh fnareoh closed this as completed Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

No branches or pull requests

2 participants