Skip to content

[Bug]: Nan values in scatter 3d plot show in black colour when alpha parameter is passed. #25446

@ricmperes

Description

@ricmperes

Bug summary

In a projection='3d' axis, a scatter plot with the c argument to colour the points is showing black markers in the position of nan values if the alpha argument is passed. If the alpha argument is not present, the nan values are not displayed, as expected. If the alpha argument is present, even with alpha = 1, the markers are coloured black.

Code for reproduction

n_x = 200
n_y = 1
n_z = 200

_x = np.linspace(-10,10,n_x)
_y = 0 
_z = np.linspace(-10,10,n_z)

_xx, _yy, _zz = np.meshgrid(_x, _y, _z, indexing='ij')
c = np.array(np.arange(n_x*n_y*n_z, dtype = float).reshape(n_x,n_y,n_z))
c[int(n_x/4):int(n_x/2),:,:] = np.nan

fig = plt.figure(figsize=(12, 5))
ax0 = fig.add_subplot(121, projection='3d')
ax0.scatter(_xx, _yy, _zz, c = c, marker = 's')
ax0.set_title('`alpha` OFF')
ax1 = fig.add_subplot(122, projection='3d')
ax1.set_title('`alpha` ON')
scat3d = ax1.scatter(_xx, _yy, _zz, c = c, 
                     marker = 's', alpha = 1)

plt.show()

Actual outcome

download

Expected outcome

download

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.7.0

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.10.9

Jupyter version

6.5.2

Installation

conda

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