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

Skip to content

Commit 164e650

Browse files
authored
Merge pull request #18136 from tomneep/mplot3d_scatter_sizes
Sort 3d sizes along with other properties
2 parents 1c55901 + edeb238 commit 164e650

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
@@ -482,6 +482,7 @@ def set_3d_properties(self, zs, zdir):
482482
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
483483
self._facecolor3d = self.get_facecolor()
484484
self._edgecolor3d = self.get_edgecolor()
485+
self._sizes3d = self.get_sizes()
485486
self.stale = True
486487

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

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

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

515520
self.set_edgecolors(ecs)
516521
self.set_facecolors(fcs)
522+
self.set_sizes(sizes)
517523

518524
PathCollection.set_offsets(self, vps)
519525

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)