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

Skip to content

Sort 3d sizes along with other properties #18136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def set_3d_properties(self, zs, zdir):
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
self._facecolor3d = self.get_facecolor()
self._edgecolor3d = self.get_edgecolor()
self._sizes3d = self.get_sizes()
self.stale = True

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

sizes = self._sizes3d

# Sort the points based on z coordinates
# Performance optimization: Create a sorted index array and reorder
# points and point properties according to the index array
Expand All @@ -506,13 +509,16 @@ def do_3d_projection(self, renderer):
vys = vys[z_markers_idx]
fcs = fcs[z_markers_idx]
ecs = ecs[z_markers_idx]
if len(sizes) > 1:
sizes = sizes[z_markers_idx]
vps = np.column_stack((vxs, vys))

fcs = mcolors.to_rgba_array(fcs, self._alpha)
ecs = mcolors.to_rgba_array(ecs, self._alpha)

self.set_edgecolors(ecs)
self.set_facecolors(fcs)
self.set_sizes(sizes)

PathCollection.set_offsets(self, vps)

Expand Down
24 changes: 24 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,30 @@ def test_scatter3d_color():
color='b', marker='s')


@check_figures_equal(extensions=['png'])
def test_scatter3d_size(fig_ref, fig_test):
"""Test that large markers in correct position (issue #18135)"""
x = np.arange(10)
x, y = np.meshgrid(x, x)
z = np.arange(100).reshape(10, 10)

s = np.full(z.shape, 5)
s[0, 0] = 100
s[-1, 0] = 100
s[0, -1] = 100
s[-1, -1] = 100

ax_ref = fig_ref.gca(projection='3d')
ax_test = fig_test.gca(projection='3d')

small = np.ma.masked_array(z, s == 100, dtype=float)
large = np.ma.masked_array(z, s != 100, dtype=float)

ax_ref.scatter(x, y, large, s=100, c="C0", alpha=1)
ax_ref.scatter(x, y, small, s=5, c="C0", alpha=1)
ax_test.scatter(x, y, z, s=s, c="C0", alpha=1)


@pytest.mark.parametrize('azim', [-50, 130]) # yellow first, blue first
@check_figures_equal(extensions=['png'])
def test_marker_draw_order_data_reversed(fig_test, fig_ref, azim):
Expand Down