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 problem with legend if data has NaN's [backport to 1.4.x] #3613
Conversation
This looks reasonable to me. Someone who understand the transform stack better than I do should take a look at this. |
Seems like a reasonable fix. It's a shame it has to copy all of the vertices (which can be quite large) to do it, though. Maybe just use the Numpy error context manager to suppress the warning instead? |
Yes, using the context manager to suppress the warning will be faster and will use less resources. We can use: np.seterr(invalid='ignore')
... Or: with np.errstate(invalid='ignore'):
dx0 = np.sign(vertices[:, 0] - x0)
dy0 = np.sign(vertices[:, 1] - y0)
dx1 = np.sign(vertices[:, 0] - x1)
dy1 = np.sign(vertices[:, 1] - y1)
... Any preference? |
Let's use the context manager. Setting it globally will hide legitimate warnings in user code. Thanks! |
Ok, should I change the code and do the pull request? |
Just make a new commit and add it to this branch. The PR tracks the branch from your repo, not the commit. You can even do a force-push to your repo and expunge all record of the current commit. |
304ddd3
to
76951f0
Compare
If data has NaN's and plot has a legend, matplotlib throws a RuntimeWarning on lines 651-654. Solution is ignore it.
The test failure on 2.7 is odd; it is not just the usual unrelated timeout or other Travis glitch. |
I have noticed that one go by every so often and it is normally a travis glitch. Restarted the tests on 2.7. |
it worked, thanks. |
Fix problem with legend if data has NaN's [backport to 1.4.x]
@tacaswell, would you do the backport, please? |
Fix problem with legend if data has NaN's [backport to 1.4.x]
back-ported as 86f9f9c |
If data has NaN's and the plot a legend with parameter 'best', matplotlib throws the following RuntimeWarning:
...\matplotlib\transforms.py:651: RuntimeWarning: invalid value encountered in sign
dx0 = np.sign(vertices[:, 0] - x0)
...\matplotlib\transforms.py:652: RuntimeWarning: invalid value encountered in sign
dy0 = np.sign(vertices[:, 1] - y0)
...\matplotlib\transforms.py:653: RuntimeWarning: invalid value encountered in sign
dx1 = np.sign(vertices[:, 0] - x1)
...\matplotlib\transforms.py:654: RuntimeWarning: invalid value encountered in sign
dy1 = np.sign(vertices[:, 1] - y1)
The following code reproduces this RuntimeWarning:
plt.plot([1,2,np.nan,4,5], label='test')
plt.legend(loc='best')
The solution is to check for NaN's in data and delete those rows, as suggested.