Skip to content

[Bug]: scatter set_facecolor does not work if the colors were manually set during the initial scatter call #27555

Open
@scottshambaugh

Description

@scottshambaugh

Bug summary

If colors of scatter points are set during the initial call, then later calls of set_facecolor to that artist fail to update the colors. set_edgecolor works as expected. This is happening in 2D and 3D scatter plots (fixing the 2D case should fix both).

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib as mpl
cmap = mpl.colormaps['viridis']
x = np.ones(10)
y = np.linspace(0, 1, 10)

fig, ax = plt.subplots()
scat = ax.scatter(x, y, c=y, cmap='viridis', s=20)
colors = cmap(np.roll(y, 3))
scat.set_edgecolor(colors)
scat.set_facecolor(colors)

Actual outcome

image

Expected outcome

Result if colors are not passed in the initial scatter call are as expected:

fig, ax = plt.subplots()
scat = ax.scatter(x, y, s=20)
colors = cmap(np.roll(y, 3))
scat.set_edgecolor(colors)
scat.set_facecolor(colors)

image

Additional information

No response

Operating system

No response

Matplotlib Version

latest main

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions