Skip to content

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

Closed

Description

@MaozGelbart

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

Activity

  1. story645 commented on May 15, 2020

    @story645
    Member

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

  2. QuLogic commented on May 15, 2020

    @QuLogic
    Member

    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.

  3. added this to the v3.2.2 milestone on May 15, 2020
  4. mwaskom commented on May 23, 2020

    @mwaskom

    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?

  5. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on May 23, 2020
  6. added a commit that references this issue on May 23, 2020
    d84f4a7
  7. tacaswell commented on May 23, 2020

    @tacaswell
    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.

  8. mwaskom commented on May 23, 2020

    @mwaskom

    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...

  9. tacaswell commented on May 23, 2020

    @tacaswell
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.topic: color/color & colormaps

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions