Skip to content

Commit 52fd461

Browse files
committed
Split attribute sorting into Patch3DCollection.draw.
This moves attribute sorting from `Patch3DCollection.do_3d_projection` into a new `draw` method. Sorted attributes are added only temporarily, so there is no reason to cache the original values anywhere, and thus all overridden setters can be dropped.
1 parent 6293052 commit 52fd461

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

‎lib/mpl_toolkits/mplot3d/art3d.py‎

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,6 @@ def set_depthshade(self, depthshade):
454454
self._depthshade = depthshade
455455
self.stale = True
456456

457-
def set_facecolor(self, c):
458-
# docstring inherited
459-
super().set_facecolor(c)
460-
self._facecolor3d = self.get_facecolor()
461-
462-
def set_edgecolor(self, c):
463-
# docstring inherited
464-
super().set_edgecolor(c)
465-
self._edgecolor3d = self.get_edgecolor()
466-
467457
def set_sort_zpos(self, val):
468458
"""Set the position to use for z-sorting."""
469459
self._sort_zpos = val
@@ -480,32 +470,39 @@ def set_3d_properties(self, zs, zdir):
480470
xs = []
481471
ys = []
482472
self._offsets3d = juggle_axes(xs, ys, np.atleast_1d(zs), zdir)
483-
self._facecolor3d = self.get_facecolor()
484-
self._edgecolor3d = self.get_edgecolor()
485473
self.stale = True
486474

487475
@cbook._delete_parameter('3.4', 'renderer')
488476
def do_3d_projection(self, renderer=None):
489477
xs, ys, zs = self._offsets3d
490478
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
491479
self.axes.M)
492-
493-
fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
494-
self._facecolor3d)
495-
fcs = mcolors.to_rgba_array(fcs, self._alpha)
496-
super().set_facecolor(fcs)
497-
498-
ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
499-
self._edgecolor3d)
500-
ecs = mcolors.to_rgba_array(ecs, self._alpha)
501-
super().set_edgecolor(ecs)
502-
super().set_offsets(np.column_stack([vxs, vys]))
503-
504480
if vzs.size > 0:
505481
return min(vzs)
506482
else:
507483
return np.nan
508484

485+
@artist.allow_rasterization
486+
def draw(self, renderer):
487+
# docstring inherited
488+
xs, ys, zs = self._offsets3d
489+
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
490+
self.axes.M)
491+
492+
fcs = self.get_facecolor()
493+
ecs = self.get_edgecolor()
494+
if self._depthshade:
495+
fcs = _zalpha(fcs, vzs)
496+
ecs = _zalpha(ecs, vzs)
497+
fcs = mcolors.to_rgba_array(fcs, self._alpha)
498+
ecs = mcolors.to_rgba_array(ecs, self._alpha)
499+
500+
offsets = np.column_stack([vxs, vys])
501+
502+
with cbook._setattr_cm(self, _edgecolors=ecs, _facecolors=fcs,
503+
_offsets=offsets):
504+
super().draw(renderer)
505+
509506

510507
class Path3DCollection(PathCollection):
511508
"""

0 commit comments

Comments
 (0)