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

Skip to content

Commit 887b51e

Browse files
authored
Merge pull request #26249 from artemshekh/fix-axes3d.scatter-color-handling
FIX: axes3d.scatter color parameter doesn't decrease in size for non-finite coordinate inputs.
2 parents 6cc7b84 + b0f0781 commit 887b51e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,11 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
23102310
*[np.ravel(np.ma.filled(t, np.nan)) for t in [xs, ys, zs]])
23112311
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
23122312

2313-
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2313+
xs, ys, zs, s, c, color = cbook.delete_masked_points(
2314+
xs, ys, zs, s, c, kwargs.get('color', None)
2315+
)
2316+
if kwargs.get('color', None):
2317+
kwargs['color'] = color
23142318

23152319
# For xs and ys, 2D scatter() will do the copying.
23162320
if np.may_share_memory(zs_orig, zs): # Avoid unnecessary copies.

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,3 +2208,29 @@ def test_mutating_input_arrays_y_and_z(fig_test, fig_ref):
22082208
y = [0.0, 0.0, 0.0]
22092209
z = [0.0, 0.0, 0.0]
22102210
ax2.plot(x, y, z, 'o-')
2211+
2212+
2213+
def test_scatter_masked_color():
2214+
"""
2215+
Test color parameter usage with non-finite coordinate arrays.
2216+
2217+
GH#26236
2218+
"""
2219+
2220+
x = [np.nan, 1, 2, 1]
2221+
y = [0, np.inf, 2, 1]
2222+
z = [0, 1, -np.inf, 1]
2223+
colors = [
2224+
[0.0, 0.0, 0.0, 1],
2225+
[0.0, 0.0, 0.0, 1],
2226+
[0.0, 0.0, 0.0, 1],
2227+
[0.0, 0.0, 0.0, 1]
2228+
]
2229+
2230+
fig = plt.figure()
2231+
ax = fig.add_subplot(projection='3d')
2232+
path3d = ax.scatter(x, y, z, color=colors)
2233+
2234+
# Assert sizes' equality
2235+
assert len(path3d.get_offsets()) ==\
2236+
len(super(type(path3d), path3d).get_facecolors())

0 commit comments

Comments
 (0)