Skip to content
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

BUG: Fix fill_between when NaN values are present #1140

Merged
merged 3 commits into from Aug 25, 2012

Conversation

tonysyu
Copy link
Contributor

@tonysyu tonysyu commented Aug 23, 2012

When NaN values are passed to fill_between, the nan value gets replaced by a value at the origin. This PR reuses the function's mask handling to produce a more user-friendly result.

Here's an example demonstrating the issue.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 50)
y = np.sin(x)
y[10] = np.nan
y[30] = np.nan
plt.fill_between(x, y)
plt.show()

@efiring
Copy link
Member

efiring commented Aug 24, 2012

I think a simpler and more obvious way to accomplish this is change np.asanyarray to np.ma.masked_invalid in the three lines near the top of the function. There is also a cbook.safe_masked_invalid, but it has no docstring, and I don't know what danger it is protecting against--even though I see that I was the one who added it, back in 2009. I suspect it might have been a problem with earlier numpy versions, because a little quick checking does not turn up anything that ma.masked_invalid can't handle.

@tonysyu
Copy link
Contributor Author

tonysyu commented Aug 25, 2012

@efiring Indeed, np.ma.masked_invalid is much cleaner. Updated PR.

efiring added a commit that referenced this pull request Aug 25, 2012
BUG: Fix fill_between when NaN values are present
@efiring efiring merged commit 4832bac into matplotlib:master Aug 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants