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

matplotlib scatter shifts color codes when NaN is present #3489

Closed
Morisset opened this issue Sep 9, 2014 · 8 comments
Closed

matplotlib scatter shifts color codes when NaN is present #3489

Morisset opened this issue Sep 9, 2014 · 8 comments
Labels
API: consistency Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues mentored: hackathon
Milestone

Comments

@Morisset
Copy link

Morisset commented Sep 9, 2014

I want to plot some data with a given color code. For example:

x = np.array([0, 1, 2, 3])
b = np.array([1, 0, 2, 3])
colors = np.array(['g', 'r', 'b', 'y'])
plt.scatter(x, b**2, color=colors)

Great, all the points appear, each one with its color. Now, some data is missing:

plt.figure()
plt.scatter(x, np.log10(b), color=colors)

Here comes the problem: the x=1 data is missing (log(0)=NaN), but the colors are skipping this point and the x=2 point is red, not blue. The solution can be:

y = np.log10(b)
mask = np.isfinite(y)
plt.scatter(x[mask], y[mask], color=colors[mask])

but I feel it so uncomfortable to do this... Any other way? Is this a kind of bug?
Thanks,
Christophe

@tacaswell tacaswell added this to the v1.4.x milestone Sep 9, 2014
@efiring
Copy link
Member

efiring commented Sep 10, 2014

Yes, it's a bug; but there is a function call in scatter that is supposed to be handling exactly this situation, and I don't see immediately why it is failing to do so in this instance. It looks like calling the function, cbook.delete_masked_points(), directly with the arguments works as intended, so it appears that something is getting fouled up prior to the function call.

@efiring
Copy link
Member

efiring commented Sep 10, 2014

Aha! @tacaswell was right--the problem was the API. The correct kwarg is "c", not "colors". I don't know what to do about that; maybe pop "colors" off the kwarg list and use it as a synonym for "c"?

@tacaswell
Copy link
Member

Right by dumb luck!

And that sounds reasonable to me use color as an alias for c.

In fact right now you can pass in both c and color and in some cases it looks like color will over-ride c.

It also looks like facecolor, facecolors, edgecolor and edgecolors will all also have similar problems.

[edit to finish sentence]

@WeatherGod
Copy link
Member

All the more reason for some sort of kwarg normalization function discussed
yesterday...

On Tue, Sep 9, 2014 at 11:01 PM, Thomas A Caswell notifications@github.com
wrote:

Right by dumb luck!

And that sounds reasonable to me In fact right now you can pass in both c
and color and in some cases it looks like color will over-ride c.

It also looks like facecolor, facecolors, edgecolor and edgecolors will
all also have similar problems.


Reply to this email directly or view it on GitHub
#3489 (comment)
.

@tacaswell tacaswell modified the milestones: v1.4.2, v1.4.x Oct 17, 2014
@tacaswell tacaswell modified the milestones: v1.4.3, v1.4.x Jan 27, 2015
@tacaswell tacaswell added the Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label Feb 7, 2015
@tacaswell tacaswell modified the milestones: 1.5.0, v1.4.x Feb 7, 2015
@tacaswell tacaswell modified the milestones: proposed next point release, next point release Aug 9, 2015
@story645
Copy link
Member

story645 commented Jun 1, 2016

does #4079 also fix this one?

@efiring
Copy link
Member

efiring commented Jun 1, 2016

@story645 I suspect it does, possibly in conjunction with later changes. Would you test v2.x with the example given above, please? If you find that the bug no longer appears, I will close this issue.

@story645
Copy link
Member

story645 commented Dec 5, 2016

Sorry had totally spaced out on this. Tested and still broken, but now there's #7570

@tacaswell
Copy link
Member

@story645 Could you review #7570 ?

@tacaswell tacaswell modified the milestones: 2.0.1 (next bug fix release), 2.1 (next point release) Dec 5, 2016
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.0.1 (next bug fix release) Dec 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: consistency Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues mentored: hackathon
Projects
None yet
Development

No branches or pull requests

6 participants