Skip to content

[Bug]: Scatter legend marker missing with initial nan value in color #26274

Open
@max3-2

Description

@max3-2

Bug summary

Plotting a scatter where c= is a sequence with the initial value being nan will have the legend entry showing text only

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 1, 50)
y = np.linspace(-1, 1, 50)
c = np.linspace(10, 100, 50)
c_nan = np.linspace(10, 100, 50)
c_nan[0] = np.nan

fig, ax = plt.subplots()
line1 = ax.scatter(x, y, c=c, s=12, label='Test 1')
line2 = ax.scatter(x * 2, y * 2, c=c_nan, s=12, label='Test 2')
ax.legend()
plt.show()

Actual outcome

bugreport

Expected outcome

Have each legend entry show a symbol

Additional information

No response

Operating system

WIndows

Matplotlib Version

3.6.3

Matplotlib Backend

Qt5Agg

Python version

3.10.x

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions