Skip to content

Errorbar does not plot errorbars centered on the marker #3400

Closed as not planned

Description

@quovatis

Using errorbar does not properly center the errorbar on the marker. See the following example and output. The issue persists in the legend as well. The errorbar is a few pixels off center and changing the linewidth does not solve the issue. snap kwarg has no effect either. I have reproduced this using matplotlib 1.2.1 and 1.3.1 on Mac OSX 10.8.4.

import matplotlib.pyplot as plt
plt.errorbar([1],[1],[0.1],fmt='k^',capsize=5,capthick=2,ms=9,markerfacecolor='none',mew=2)
plt.show()

errorbar
legend

Activity

  1. added this to the v1.4.x milestone on Aug 22, 2014
  2. jenshnielsen commented on Aug 22, 2014

    @jenshnielsen
    Member

    I can reproduce this in the gui Qt4 and Mac OSx backends. It does look correct in saved png and pdf files thou.

    Edit: This is with 1.4rc4

  3. quovatis commented on Aug 22, 2014

    @quovatis
    Author

    It persists in my saved png files. In fact, the images I uploaded were from a saved png.

  4. fcolas commented on Aug 25, 2014

    @fcolas

    On ubuntu, using Qt4agg, the line appears also shifted but on the other side.
    But on closer inspection, it's rather the markers that are shifted since the line is aligned with the ticks.

    issue3400_qt4agg_ubuntu

    When saving from the gui (or using savefig()), it doesn't happen.

    import matplotlib as plt
    plt.xlim((0.897, 1.103))
    plt.errorbar([1],[1],[0.1],fmt='k^',capsize=5,capthick=2,ms=9,markerfacecolor='none',mew=2, label='a')
    plt.legend()
    plt.show()

    (Also, I don't understand why the marker is shown twice in the legend.)

  5. jenshnielsen commented on Aug 25, 2014

    @jenshnielsen
    Member

    The legend normally shows two points connected by the line style used. You can customise that with the numpoints argument to legend

  6. WeatherGod commented on Aug 25, 2014

    @WeatherGod
    Member

    IIRC, there was some work during SciPy 2013 to deal with positioning issues
    of vertical and horizontal lines (at the time, it was primarially to deal
    with spine alignment with ticks). Perhaps markers got left behind in this
    effort?

    On Mon, Aug 25, 2014 at 10:17 AM, Jens H Nielsen notifications@github.com
    wrote:

    The legend normally shows two points connected by the line style used. You
    can customise that with the numpoints argument to legend

    —
    Reply to this email directly or view it on GitHub
    #3400 (comment)
    .

  7. mdboom commented on Aug 25, 2014

    @mdboom
    Member

    The issue is this (and it's a tricky one to solve). matplotlib includes a feature called "pixel snapping" which helps to avoid fuzzy-looking anti-aliasing by aligning to pixels. When you have a line with a width that is an odd number of pixels, it is aligned to pixel centers. When you have a line with a width that is an even number of pixels, it is aligned to pixel edges. In this example, the line is an odd width (1), while the marker line is an even width (2). So their alignment is a half pixel different. How this is should probably work is that the alignment is determined by the line, and never by the marker. Unfortunately, as it stands now, the marker drawing doesn't know about the width of the line that it's associated with (only the width of the marker edge itself). So that will require some reorganization of code to get right.

    In the meantime, as a workaround: you can (a) set the marker edge width to the same as the line edge width or (b) output to any of the vector formats which do not have this snapping behavior (since something else ultimately does the rendering later).

  8. quovatis commented on Aug 25, 2014

    @quovatis
    Author

    I get the same behavior using the same marker edge width and line width, so I don't accept that explanation. Upon inspection it is indeed the line and not the marker that is off. The marker aligns with the tickmarks, but the error line is 1 pixel off.
    What vector formats do not have this snapping behavior?

  9. tacaswell commented on Aug 25, 2014

    @tacaswell
    Member

    I thought I tried to turn snapping off and it didn't make a difference.

  10. WeatherGod commented on Aug 25, 2014

    @WeatherGod
    Member

    Which backend are you using? Also, which version of matplotlib. This might
    be backend-specific as I am able to reproduce what Francis reports.

    SVG, EPS and PDF are all vector formats that saves the raw vector data. It
    would then be up to their respective viewers to render that data correctly.
    Our renderer appears to be incorrect in some cases.

    On Mon, Aug 25, 2014 at 12:42 PM, quovatis notifications@github.com wrote:

    I get the same behavior using the same marker edge width and line width,
    so I don't accept that explanation. Upon inspection it is indeed the line
    and not the marker that is off. The marker aligns with the tickmarks, but
    the error line is 1 pixel off.
    What vector formats do not have this snapping behavior?

    —
    Reply to this email directly or view it on GitHub
    #3400 (comment)
    .

  11. quovatis commented on Aug 25, 2014

    @quovatis
    Author

    As was in my initial post, I'm using matplotlib 1.3.1 and MacOSX. I've tried various combinations of marker edge widths and line widths, and the problem persists in all combinations.

  12. tacaswell commented on Aug 25, 2014

    @tacaswell
    Member

    I can reproduce this on master.

  13. removed this from the v1.4.x milestone on Feb 7, 2015
  14. 4 remaining items

  15. removed this from the milestone on Jul 17, 2015
  16. Knusper commented on Sep 6, 2017

    @Knusper

    Is this bug still relevant? I see it in 1.5.3 on my work machine. However, when saving the figure as PDF it is not there....

  17. anntzer commented on Sep 6, 2017

    @anntzer
    Contributor

    See #3400 (comment).

    I think this is due (as usual) to stamping -- looks like mpl_cairo does not display the issue (if snapping is turned off).

  18. modified the milestones: , on Oct 3, 2017
  19. quovatis commented on Mar 1, 2018

    @quovatis
    Author

    Still present in 2.1. Tested macosx, wx, and tkagg backends, and it's present in all of them. Issue is not present in Cairo.

  20. dstansby commented on Oct 26, 2018

    @dstansby
    Member

    Still an issue in 3.0.1

  21. github-actions commented on Mar 6, 2023

    @github-actions

    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!

  22. jklymak commented on Mar 6, 2023

    @jklymak
    Member

    This is pixel snapping - plt.errorbar([1],[1],[0.1],fmt='k^',capsize=5,capthick=2,ms=9,markerfacecolor='none',mew=2, label='a', snap=False) is centered appropriately, and this will not be apparent with high DPI or vector formats. I'll close, but feel free to re-open if folks disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions