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

Skip to content

FIX: axes3d.scatter color parameter doesn't decrease in size for non-finite coordinate inputs. #26249

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,11 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
*[np.ravel(np.ma.filled(t, np.nan)) for t in [xs, ys, zs]])
s = np.ma.ravel(s) # This doesn't have to match x, y in size.

xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
xs, ys, zs, s, c, color = cbook.delete_masked_points(
xs, ys, zs, s, c, kwargs.get('color', None)
)
if kwargs.get('color', None):
kwargs['color'] = color

# For xs and ys, 2D scatter() will do the copying.
if np.may_share_memory(zs_orig, zs): # Avoid unnecessary copies.
Expand Down
26 changes: 26 additions & 0 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2226,3 +2226,29 @@ def test_mutating_input_arrays_y_and_z(fig_test, fig_ref):
y = [0.0, 0.0, 0.0]
z = [0.0, 0.0, 0.0]
ax2.plot(x, y, z, 'o-')


def test_scatter_masked_color():
"""
Test color parameter usage with non-finite coordinate arrays.

GH#26236
"""

x = [np.nan, 1, 2, 1]
y = [0, np.inf, 2, 1]
z = [0, 1, -np.inf, 1]
colors = [
[0.0, 0.0, 0.0, 1],
[0.0, 0.0, 0.0, 1],
[0.0, 0.0, 0.0, 1],
[0.0, 0.0, 0.0, 1]
]

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
path3d = ax.scatter(x, y, z, color=colors)

# Assert sizes' equality
assert len(path3d.get_offsets()) ==\
len(super(type(path3d), path3d).get_facecolors())