Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
ricmperes opened this issue Mar 13, 2023 · 5 comments · May be fixed by #25478
Open

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

ricmperes opened this issue Mar 13, 2023 · 5 comments · May be fixed by #25478

Comments

@ricmperes
Copy link

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

@ricmperes
Copy link
Author

In a 2d projection the issue does not happen and both alpha and nan values work as expected.

download

@tacaswell
Copy link
Member

The default color for "bad" in the color maps is (0, 0, 0, 0) which if alpha gets set to 1 is black.

My guess (without digging into the code) is that we are setting the alpha rather than multiplyin the alpha when it is set by the user....

@evgepab
Copy link

evgepab commented Mar 14, 2023

Hello! Me and @eirinikafourou are students at the Department of Management Science and Technology in Athens University of Economics and Business and as a part of our class (Applied Software Engineering) we should contribute to an OS project. Could we handle this issue?

@tacaswell
Copy link
Member

We do not really assign issues, so please feel free to work on this (or any other issue).

@oscargus
Copy link
Member

Seems like @tacaswell guess is correct:

def _maybe_depth_shade_and_sort_colors(self, color_array):
color_array = (
_zalpha(color_array, self._vzs)
if self._vzs is not None and self._depthshade
else color_array
)
if len(color_array) > 1:
color_array = color_array[self._z_markers_idx]
return mcolors.to_rgba_array(color_array, self._alpha)

The original alpha values are dropped at the first line and then a single alpha value is set at the last line.

The solution would probably be to store the original alpha values and then concatenate them back (multiplied with self._alpha) at the last line.

@ricmperes ricmperes linked a pull request Mar 16, 2023 that will close this issue
6 tasks
@oscargus oscargus linked a pull request Mar 16, 2023 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants