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

Skip to content

Commit b0f0781

Browse files
committed
FIX: axes3d.scatter color parameter doesn't decrease in size
for non-finite coordinate inputs.
1 parent f017315 commit b0f0781

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
@@ -2249,7 +2249,11 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True,
22492249
*[np.ravel(np.ma.filled(t, np.nan)) for t in [xs, ys, zs]])
22502250
s = np.ma.ravel(s) # This doesn't have to match x, y in size.
22512251

2252-
xs, ys, zs, s, c = cbook.delete_masked_points(xs, ys, zs, s, c)
2252+
xs, ys, zs, s, c, color = cbook.delete_masked_points(
2253+
xs, ys, zs, s, c, kwargs.get('color', None)
2254+
)
2255+
if kwargs.get('color', None):
2256+
kwargs['color'] = color
22532257

22542258
# For xs and ys, 2D scatter() will do the copying.
22552259
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
@@ -2226,3 +2226,29 @@ def test_mutating_input_arrays_y_and_z(fig_test, fig_ref):
22262226
y = [0.0, 0.0, 0.0]
22272227
z = [0.0, 0.0, 0.0]
22282228
ax2.plot(x, y, z, 'o-')
2229+
2230+
2231+
def test_scatter_masked_color():
2232+
"""
2233+
Test color parameter usage with non-finite coordinate arrays.
2234+
2235+
GH#26236
2236+
"""
2237+
2238+
x = [np.nan, 1, 2, 1]
2239+
y = [0, np.inf, 2, 1]
2240+
z = [0, 1, -np.inf, 1]
2241+
colors = [
2242+
[0.0, 0.0, 0.0, 1],
2243+
[0.0, 0.0, 0.0, 1],
2244+
[0.0, 0.0, 0.0, 1],
2245+
[0.0, 0.0, 0.0, 1]
2246+
]
2247+
2248+
fig = plt.figure()
2249+
ax = fig.add_subplot(projection='3d')
2250+
path3d = ax.scatter(x, y, z, color=colors)
2251+
2252+
# Assert sizes' equality
2253+
assert len(path3d.get_offsets()) ==\
2254+
len(super(type(path3d), path3d).get_facecolors())

0 commit comments

Comments
 (0)