-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: ax.bar raises for all-nan data on matplotlib 3.6.1 #24127
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
This is the PR in question: #23751 (although I have not checked is that is causing it). |
Thanks @oscargus that indeed looks like the culprit: it asks for the "next" finite value and does not handle the |
We should definitely fix this regression, but is there a better way for seaborn to be managing the colors that does not require adding and removing artists? I assume you use |
Definitely open to that but none that I am aware of! I don't think there's a public API for advancing the property cycle? AFAIK one would need to do something like
Yep, exactly. Actually in most cases I just pass empty data, but |
Just as a meta comment I guess this should not have been milestones so aggressively? The pr fixed a bug, but an old one so maybe could have waited for 3.7? |
If I understand correctly, it did work in 3.6.0 for the all-nan case, but not for a leading nan (and other non-nan values). So although a bug was fixed in 3.6.1, this was introduced there as well. (If my understanding is wrong then it could for sure have waited.) |
Summary: Matplotlib 3.6.1 has a bug with NaN handling (matplotlib/matplotlib#24127), leading to errors when running the tutorial. This implements a workaround, replacing `yerr` with NaNs with `None`. Differential Revision: D40232488 fbshipit-source-id: 5ee8343cc8ea67a302355fe0e93897a08383f862
Summary: Pull Request resolved: pytorch#1446 Matplotlib 3.6.1 has a bug with NaN handling (matplotlib/matplotlib#24127), leading to errors when running the tutorial. This implements a workaround, replacing `yerr` with NaNs with `None`. Differential Revision: D40232488 fbshipit-source-id: ccb8dab6d3d8b3798bfbc7aaf5e3f1f1390bfd9d
Summary: Pull Request resolved: pytorch#1446 Matplotlib 3.6.1 has a bug with NaN handling (matplotlib/matplotlib#24127), leading to errors when running the tutorial. This implements a workaround, replacing `yerr` with NaNs with `None`. Differential Revision: D40232488 fbshipit-source-id: a80a31c42ea4426638dcf864731c72e554729c00
Summary: Pull Request resolved: #1446 Matplotlib 3.6.1 has a bug with NaN handling (matplotlib/matplotlib#24127), leading to errors when running the tutorial. This implements a workaround, replacing `yerr` with NaNs with `None`. Reviewed By: ItsMrLin Differential Revision: D40232488 fbshipit-source-id: a2322d46454c96a869a93fe37aa3800db6c6ad8d
…58) * add df_to_arrays() in pymatviz/utils.py and change func signatures in pymatviz/parity.py to accept dfs and column names as well as arrays * add test_df_to_arrays() in test_utils.py and include coverage for df signature in test_parity.py * pin matplotlib below 3.6.1 until matplotlib/matplotlib#24127 resolves
✔ 15:28:08 $ git diff
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index fdac0f3560..de4a99f71d 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -2182,11 +2182,19 @@ class Axes(_AxesBase):
x0 = cbook._safe_first_finite(x0)
except (TypeError, IndexError, KeyError):
pass
+ except StopIteration:
+ # this means we found no finite element, fall back to first
+ # element unconditionally
+ x0 = cbook.safe_first_element(x0)
try:
x = cbook._safe_first_finite(xconv)
except (TypeError, IndexError, KeyError):
x = xconv
+ except StopIteration:
+ # this means we found no finite element, fall back to first
+ # element unconditionally
+ x = cbook.safe_first_element(xconv)
delist = False
if not np.iterable(dx):
I think this is the fix, need to commit it and add a test. My memory of this was that this was a 3.6 regression from 3.5 but looking at the linked issue that was clearly wrong. |
So interestingly I am still encountering this error with a recent version of matplotlib on MacOS. On a linux based system it is working as expected. Test code:
Output Linux: Output MacOS:
Here the info to the installed python versions Linux
MacOS:
|
…58) * add df_to_arrays() in pymatviz/utils.py and change func signatures in pymatviz/parity.py to accept dfs and column names as well as arrays * add test_df_to_arrays() in test_utils.py and include coverage for df signature in test_parity.py * pin matplotlib below 3.6.1 until matplotlib/matplotlib#24127 resolves
Bug summary
ax.bar
raises an exception in 3.6.1 when passed only nan data. This irrevocably breaks seaborn's histogram function (which draws and then removes a "phantom" bar to trip the color cycle).Code for reproduction
Actual outcome
Expected outcome
On 3.6.0 this returns a
BarCollection
with one Rectangle, havingnan
forx
andheight
.Additional information
I assume it's related to this bullet in the release notes:
But I don't know the context for it to investigate further (could these link to PRs?)
Further debugging:
So it's about the x position specifically.
Operating system
Macos
Matplotlib Version
3.6.1
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: