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

Skip to content

Commit 828c60b

Browse files
committed
Also sort line widths for scatter3d.
1 parent 94263ac commit 828c60b

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ def set_3d_properties(self, zs, zdir):
488488
self._facecolor3d = self.get_facecolor()
489489
self._edgecolor3d = self.get_edgecolor()
490490
self._sizes3d = self.get_sizes()
491+
self._linewidth3d = self.get_linewidth()
491492
self.stale = True
492493

493494
def do_3d_projection(self, renderer):
@@ -499,6 +500,7 @@ def do_3d_projection(self, renderer):
499500
ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
500501
self._edgecolor3d)
501502
sizes = self._sizes3d
503+
lws = self._linewidth3d
502504

503505
# Sort the points based on z coordinates
504506
# Performance optimization: Create a sorted index array and reorder
@@ -515,6 +517,8 @@ def do_3d_projection(self, renderer):
515517
ecs = ecs[z_markers_idx]
516518
if len(sizes) > 1:
517519
sizes = sizes[z_markers_idx]
520+
if len(lws) > 1:
521+
lws = lws[z_markers_idx]
518522
vps = np.column_stack((vxs, vys))
519523

520524
fcs = mcolors.to_rgba_array(fcs, self._alpha)
@@ -523,6 +527,7 @@ def do_3d_projection(self, renderer):
523527
self.set_edgecolors(ecs)
524528
self.set_facecolors(fcs)
525529
self.set_sizes(sizes)
530+
self.set_linewidth(lws)
526531

527532
PathCollection.set_offsets(self, vps)
528533

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,23 @@ def test_scatter3d_sorting(fig_ref, fig_test, depthshade):
265265
edgecolors[5:9, 1:5] = 'C6'
266266
edgecolors[5:9, 5:9] = 'C7'
267267

268-
x, y, z, sizes, facecolors, edgecolors = [
268+
linewidths = np.full(z.shape, 2)
269+
linewidths[0::2, 0::2] = 5
270+
linewidths[1::2, 1::2] = 5
271+
272+
x, y, z, sizes, facecolors, edgecolors, linewidths = [
269273
a.flatten()
270-
for a in [x, y, z, sizes, facecolors, edgecolors]
274+
for a in [x, y, z, sizes, facecolors, edgecolors, linewidths]
271275
]
272276

273277
ax_ref = fig_ref.gca(projection='3d')
274-
sets = (np.unique(a) for a in [sizes, facecolors, edgecolors])
275-
for s, fc, ec in itertools.product(*sets):
278+
sets = (np.unique(a) for a in [sizes, facecolors, edgecolors, linewidths])
279+
for s, fc, ec, lw in itertools.product(*sets):
276280
subset = (
277281
(sizes != s) |
278282
(facecolors != fc) |
279-
(edgecolors != ec)
283+
(edgecolors != ec) |
284+
(linewidths != lw)
280285
)
281286
subset = np.ma.masked_array(z, subset, dtype=float)
282287

@@ -286,12 +291,12 @@ def test_scatter3d_sorting(fig_ref, fig_test, depthshade):
286291
# would not occur for the full scatter which has multiple colors.
287292
fc = np.repeat(fc, sum(~subset.mask))
288293

289-
ax_ref.scatter(x, y, subset, s=s, fc=fc, ec=ec, alpha=1,
294+
ax_ref.scatter(x, y, subset, s=s, fc=fc, ec=ec, lw=lw, alpha=1,
290295
depthshade=depthshade)
291296

292297
ax_test = fig_test.gca(projection='3d')
293-
ax_test.scatter(x, y, z, s=sizes, fc=facecolors, ec=edgecolors, alpha=1,
294-
depthshade=depthshade)
298+
ax_test.scatter(x, y, z, s=sizes, fc=facecolors, ec=edgecolors,
299+
lw=linewidths, alpha=1, depthshade=depthshade)
295300

296301

297302
@pytest.mark.parametrize('azim', [-50, 130]) # yellow first, blue first

0 commit comments

Comments
 (0)