Skip to content

Commit 0628e6f

Browse files
jkseppanmeeseeksmachine
authored andcommitted
Backport PR #18136: Sort 3d sizes along with other properties
1 parent 8187369 commit 0628e6f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def set_3d_properties(self, zs, zdir):
481481
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
482482
self._facecolor3d = self.get_facecolor()
483483
self._edgecolor3d = self.get_edgecolor()
484+
self._sizes3d = self.get_sizes()
484485
self.stale = True
485486

486487
def do_3d_projection(self, renderer):
@@ -495,6 +496,8 @@ def do_3d_projection(self, renderer):
495496
ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
496497
self._edgecolor3d)
497498

499+
sizes = self._sizes3d
500+
498501
# Sort the points based on z coordinates
499502
# Performance optimization: Create a sorted index array and reorder
500503
# points and point properties according to the index array
@@ -506,13 +509,16 @@ def do_3d_projection(self, renderer):
506509
vys = vys[z_markers_idx]
507510
fcs = fcs[z_markers_idx]
508511
ecs = ecs[z_markers_idx]
512+
if len(sizes) > 1:
513+
sizes = sizes[z_markers_idx]
509514
vps = np.column_stack((vxs, vys))
510515

511516
fcs = mcolors.to_rgba_array(fcs, self._alpha)
512517
ecs = mcolors.to_rgba_array(ecs, self._alpha)
513518

514519
self.set_edgecolors(ecs)
515520
self.set_facecolors(fcs)
521+
self.set_sizes(sizes)
516522

517523
PathCollection.set_offsets(self, vps)
518524

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@ def test_scatter3d_color():
242242
color='b', marker='s')
243243

244244

245+
@check_figures_equal(extensions=['png'])
246+
def test_scatter3d_size(fig_ref, fig_test):
247+
"""Test that large markers in correct position (issue #18135)"""
248+
x = np.arange(10)
249+
x, y = np.meshgrid(x, x)
250+
z = np.arange(100).reshape(10, 10)
251+
252+
s = np.full(z.shape, 5)
253+
s[0, 0] = 100
254+
s[-1, 0] = 100
255+
s[0, -1] = 100
256+
s[-1, -1] = 100
257+
258+
ax_ref = fig_ref.gca(projection='3d')
259+
ax_test = fig_test.gca(projection='3d')
260+
261+
small = np.ma.masked_array(z, s == 100, dtype=float)
262+
large = np.ma.masked_array(z, s != 100, dtype=float)
263+
264+
ax_ref.scatter(x, y, large, s=100, c="C0", alpha=1)
265+
ax_ref.scatter(x, y, small, s=5, c="C0", alpha=1)
266+
ax_test.scatter(x, y, z, s=s, c="C0", alpha=1)
267+
268+
245269
@pytest.mark.parametrize('azim', [-50, 130]) # yellow first, blue first
246270
@check_figures_equal(extensions=['png'])
247271
def test_marker_draw_order_data_reversed(fig_test, fig_ref, azim):

0 commit comments

Comments
 (0)