-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix errobar order #17231
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
Fix errobar order #17231
Conversation
Thank you for working on this! However, I have several serious concerns about this. As you note, this is a un-mitigatable API change so anyone who is currently working with the return values will have their code broken with no warning. This will also break any code that is expecting to be able to look at the
A middle ground, which accepts some API breakage of not being able to find the artists in the expected lists is:
In this case we do get to fix the rendering order issues but still preserve the return type and the performance gains. Sorting out how to do a major overhaul is part of what @story645 is funded to work on under CZI grant so hopefully the major overhaul is much closer than it used to be! |
@tacaswell Thanks for getting back to me. I suspected that the change in function return would be a deal breaker, but I already did most of the changes to figure out what is going on with errorbars, so I thought I might as well put in a pull request and see what you guys think about it. I think performance is not the main issue here, if you try to plot thousands of errorbars you probably do something wrong in the first place. I'm not very familiar with the artists, etc, so the changes you suggested most likely will take quite a bit of time for me to figure out and not sure if I will find that, but I will give it a try. Any pointers are welcome too. It certainly sounds like a much more elegant solution Any ideas on how to force the svg tests to be run, it somehow skips them locally, but they seem required on travis? |
You need inkscape locally to run the svg tests (we do comparisons after rasterization rather than text comparison and use inkscape to do that rasterization). The very very fast summary of Artists is everything you see in the output is represented by an https://aosabook.org/en/matplotlib.html is a good reference for the overall architecture. |
@tacaswell. Thank you so much for taking time to explain that. Your references have been very valuable so far. The way I would think the objects should appear is:
I think I figured out how the different artists are sorted for matplotlib/lib/matplotlib/axes/_base.py Line 2728 in d4bd4e7
matplotlib/lib/matplotlib/axes/_base.py Lines 4038 to 4054 in d4bd4e7
line2D itself and added through Axes.add_line , so that it appears in AxesBase.lines at the correct position.
I think using If you agree with me on this, I think I could manage the required changes. |
The fact that all child artists are not stored in a single list is unfortunate, making it difficult to break ties by insertion order (which is more or less what we need here, I guess). I guess one option would be to complement zorder with a hidden |
I pushed another implementation of this, now as @tacaswell descriped using a single There is something wrong with the documentation, will fix that later, but other than that it seems to pass all tests. @anntzer: I think this would be part of the major overhaul @tacaswell mentioned to be done by @story645 over summer. |
I will leave this as it is for now. With @anntzer's suggestion in #17247, these changes would be unnecessary. I think however, putting errorbars into a single |
@QuLogic Thanks for working on this. Awesome to see this finally getting into matplotlib. Was happy to help. |
PR Summary
Closes #1622 #17139
This pull request fixes inconsistent behaviors of
errorbar
and the order they are drawn with respect to other elements.They way this is done, is to change how the vertical and horizontal columns of
errorbar
are plot. So far aLineCollection
was used. Unfortunately, the only way to have a collection being drawn beforeLines2D
is to change thezorder
, which let to weird behavior as well, when other objects are supposed to be plot above the error bars. The proper way to fix this would be to fix the internals of how collections and lines are stored and ordered as mentioned by @tacaswell in #1622 (comment).As the proper fix is a major rework of
matplotlib
and probably not possible in the foreseeable future, I suggest an easier fix here: The vertical and horizontal bars are drawn withLine2D
s. The only issue this causes it that the call toerrobar
now returns alist
ofLine2D
while so far aLineCollection
was returned. It would be even possible to add the errorbar caps directly to these newLine2D
making errorbars more flexible and less argument parsing necessary, but that would have created even more changes, so I kept it simple for now (let me know if that is something you think is worth it).The implementation should pass all tests, I had to change a few tests, where the test checked inconsistent behavior/wrong images caused by the old implementation.
Don't think this is a API change that can be made easily backward-compatible, or where a deprecation warning could be used, I'm open to suggestions how to resolve this. For sure might cause some issues of packages that depend on the correct return type. However, unless someone else has a good idea how this can be fixed, I think the benefits outweigh the drawbacks for now.
PR Checklist