-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Matplotlib 3.5 breaks unyt integration of error bars #21669
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
Comments
(updated because I saw that that my script was overly simplified to a point that it was actually not broken on the main branch) |
I think I got a fix, will open a PR shortly ! |
After digging a bit I'm actually stuck on this comment: matplotlib/lib/matplotlib/axes/_axes.py Line 3281 in 552e078
It seems crucial to understand why this assumption was made in matplotlib, and wether it complies with NEP 18 (array_function protocol). |
I think(??) I got this belief from pint, but not sure either. OTOH, is there any thing we can do to convert unitful arraylikes to actual arrays that 1) works across unit libs and 2) does not destroy units? |
If you’re handed an It might also help to have mock unit libraries (or even directly testing extant unit libraries) in matplotlib’s test suite as this kind of change seems to happen relatively often and you’re not depending on downstream libraries to alert you to breakage. |
The case pointed out by @neutrinoceros is already (should?) only done when the input is not a ndarray or subclass thereof. |
Correct, but the way it's implemented currently behaves weirdly when the input is a tuple of arrays |
Ah, fair enough. |
We do have a mock unit library. If downstream libraries want to add new ones (and tests) I'm sure we would entertain that. I'm not sure we will accept testing every possible downstream library that may have decided to add units. OTOH we should specify exactly what we will accept in terms of units so downstream libraries have consistent rules. This has been a problem for years, and no one has fixed it, so we play whack-a-mole. Hopefully there is light at the end of the tunnel with the upcoming NASA grant perhaps supporting a specification and interface overhaul. Please |
Well unyt isn't new to this game, I think it's maybe the third biggest player after pint and astropy, but clearly we've missed an opportunity to catch this much earlier by testing only against final releases, so I'll try to fix this on our end to try and improve the situation for everyone in the future. |
Ah then I guess a concrete improvement would be a test that directly exercises the tuple of unit arrays case for errorbar. Sorry for the off-the-cuff peanut gallery advice. |
Going back to the specific problem here: is there a way to cast a 2-tuple of unyt arrays into a (2, N) unyt array? (... that is not unyt-specific...) |
@anntzer, perhaps something like this?
|
Ah, thanks for the suggestion. |
Note that this doesn't work with two unyt arrays unless they have the exact same unit (not just coercible ones), but other than that this was also my best guess, and it's probably good enough indeed. |
Update: @ngoldbaum has a working patch for the problem I mentioned in my previous reply here yt-project/unyt#211, so now I have no reserves left to express on this approach |
Do we need the errors to be a 2, N array, versus two N-arrays? I assume the unyt 1-D arrays cast, so isn't the solution from our side to just have |
Technically, the docs state that |
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
Discovered this in unyt's daily CI jobs: https://github.com/yt-project/unyt/actions
Code for reproduction
Actual outcome
detailed raceback
Expected outcome
This is the output figure with matplotlib 3.4.3

Additional information
The regression bisects to #19526 (8cd22b4)
I note that if replace the last line with
(passing a single array instead of a tuple), it doesn't break on the main branch.
Operating system
Unbuntu
Matplotlib Version
3.5.0
Matplotlib Backend
not relevant (I get an identical error with the 'agg' backend)
Python version
tested on 3.7 to 3.9
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: