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

Skip to content

Correctly handle 'none' facecolors in do_3d_projection #18060

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

Closed
wants to merge 1 commit into from
Closed
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
31 changes: 13 additions & 18 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,33 +487,28 @@ def do_3d_projection(self, renderer):
xs, ys, zs = self._offsets3d
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
self._facecolor3d)
fcs = mcolors.to_rgba_array(fcs, self._alpha)
self.set_facecolors(fcs)

ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
self._edgecolor3d)

# 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
z_markers_idx = np.argsort(vzs)[::-1]

# Re-order items
vzs = vzs[z_markers_idx]
vxs = vxs[z_markers_idx]
vys = vys[z_markers_idx]
fcs = fcs[z_markers_idx]
ecs = ecs[z_markers_idx]
vps = np.column_stack((vxs, vys))
if len(self._facecolor3d):
fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
self._facecolor3d)
fcs = mcolors.to_rgba_array(fcs, self._alpha)
fcs = fcs[z_markers_idx]
self.set_facecolors(fcs)

fcs = mcolors.to_rgba_array(fcs, self._alpha)
ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
self._edgecolor3d)
ecs = ecs[z_markers_idx]
ecs = mcolors.to_rgba_array(ecs, self._alpha)

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

vzs = vzs[z_markers_idx]
vxs = vxs[z_markers_idx]
vys = vys[z_markers_idx]
vps = np.column_stack((vxs, vys))
PathCollection.set_offsets(self, vps)

return np.min(vzs) if vzs.size else np.nan
Expand Down
8 changes: 8 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def test_scatter3d():
z[-1] = 0 # Check that scatter() copies the data.


def test_scatter3d_nonfilledmarker():
# Check that scattering a non-filled marker works
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(np.arange(10), np.arange(10), np.arange(10), marker='x')
fig.canvas.draw()


@mpl3d_image_comparison(['scatter3d_color.png'])
def test_scatter3d_color():
fig = plt.figure()
Expand Down