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

Scatter produce multiple colors for a single RGB/RGBA input #17423

Closed
MaozGelbart opened this issue May 15, 2020 · 6 comments · Fixed by #17499
Closed

Scatter produce multiple colors for a single RGB/RGBA input #17423

MaozGelbart opened this issue May 15, 2020 · 6 comments · Fixed by #17499
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/color & colormaps
Milestone

Comments

@MaozGelbart
Copy link
Contributor

Bug report

Bug summary

Scatter docs say that in order to provide a single RGB/RGBA color for all scatter elements, it is required to pass a 2D array with a single row for c argument input:

If you want to specify the same RGB or RGBA value for all points, use a 2-D array with a single row. Otherwise, value- matching will have precedence in case of a size matching with x and y.

When x/y shape is 3 and RGB is passed as a 2D array with a single row (e.g. c=[[1, 0.5, 0.05]]), or when x/y shape is 4 and RGBA is passed as a 2D array with a single row, the plot elements have several different colors (taken from the default colormap?) while all should have the same color. The problem occurs for both plt.scatter and ax.scatter calls, and also if c input is provided as a numpy array of shape (1,3) for RGB or (1,4) for RGBA instead of a nested list.

Code for reproduction

import matplotlib.pyplot as plt
plt.scatter(range(3), range(3), c=[[1, 0.5, 0.05]])
#alternatively, for RGBA scenario
plt.scatter(range(4), range(4), c=[[1, 0.5, 0.05, 1]])

Actual outcome
840-mpl

Expected outcome
All points have the same color: RGB (1, 0.5, 0.05).

Matplotlib version

  • Operating system: Linux
  • Matplotlib version: 3.2.1
  • Matplotlib backend (print(matplotlib.get_backend())): agg
  • Python version: 3.7.3

Matplotlib installed through pip

@story645
Copy link
Member

This is a regression bug because it works as expected on 3.1.2
image

@QuLogic
Copy link
Member

QuLogic commented May 15, 2020

Bisects to 5a5c2f6, or #13959 by @efiring.

I'm not actually sure why we want to flatten c since the docs say "If you want to specify the same RGB or RGBA value for all points, use a 2-D array with a single row.", but it should work if c is the same length as x/y.

@mwaskom
Copy link

mwaskom commented May 23, 2020

IMO this is a pretty serious regression; it makes seaborn plots wrong with no straightforward way for the user to work around it. Could it please get a release critical tag?

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label May 23, 2020
tacaswell added a commit to tacaswell/matplotlib that referenced this issue May 23, 2020
@tacaswell
Copy link
Member

If you know ahead of time that you want to specify an RGG(A) color not values to be colormapped you can use the color kwarg which has none of the ambiguity.

See #17499 for fix.

@mwaskom
Copy link

mwaskom commented May 23, 2020

seaborn.scatterplot can produce varying-color scatterplots though. It would be possible to check the shape of the color array after semantic mapping and conditionally dispatch to different matplotlib kwargs, but boy would it be messy...

@tacaswell
Copy link
Member

We currently have that code in mpl and it is rather messy (which is why it keeps breaking :/ )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: color/color & colormaps
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants