Skip to content

Commit 264f5c9

Browse files
committed
Add accessors for 3D collection's depth shading.
1 parent e6d9cbb commit 264f5c9

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,22 @@ def __init__(self, *args, zs=0, zdir='z', depthshade=True, **kwargs):
403403
super().__init__(*args, **kwargs)
404404
self.set_3d_properties(zs, zdir)
405405

406+
def get_depthshade(self):
407+
return self._depthshade
408+
409+
def set_depthshade(self, depthshade):
410+
"""
411+
Set whether depth shading is performed on collection members.
412+
413+
Parameters
414+
----------
415+
depthshade : bool
416+
Whether to shade the patches in order to give the appearance of
417+
depth.
418+
"""
419+
self._depthshade = depthshade
420+
self.stale = True
421+
406422
def set_facecolor(self, c):
407423
# docstring inherited
408424
super().set_facecolor(c)
@@ -501,6 +517,22 @@ def set_3d_properties(self, zs, zdir):
501517
self._linewidth3d = self.get_linewidth()
502518
self.stale = True
503519

520+
def get_depthshade(self):
521+
return self._depthshade
522+
523+
def set_depthshade(self, depthshade):
524+
"""
525+
Set whether depth shading is performed on collection members.
526+
527+
Parameters
528+
----------
529+
depthshade : bool
530+
Whether to shade the patches in order to give the appearance of
531+
depth.
532+
"""
533+
self._depthshade = depthshade
534+
self.stale = True
535+
504536
def set_facecolor(self, c):
505537
# docstring inherited
506538
super().set_facecolor(c)

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,15 @@ def test_scatter3d_modification(fig_ref, fig_test):
251251
marker='o')
252252
c.set_facecolor('C1')
253253
c.set_edgecolor('C2')
254+
c.set_alpha([0.3, 0.7] * 5)
255+
c.set_depthshade(False)
254256
c.set_sizes(np.full(10, 75))
255257
c.set_linewidths(3)
256258

257259
ax_ref = fig_ref.add_subplot(projection='3d')
258260
ax_ref.scatter(np.arange(10), np.arange(10), np.arange(10), marker='o',
259-
facecolor='C1', edgecolor='C2', s=75, linewidths=3)
261+
facecolor='C1', edgecolor='C2', alpha=[0.3, 0.7] * 5,
262+
depthshade=False, s=75, linewidths=3)
260263

261264

262265
@pytest.mark.parametrize('depthshade', [True, False])
@@ -552,10 +555,13 @@ def test_patch_collection_modification(fig_test, fig_ref):
552555
ax_test.add_collection3d(c)
553556
c.set_edgecolor('C2')
554557
c.set_facecolor('C3')
558+
c.set_alpha(0.7)
559+
c.set_depthshade(False)
555560

556561
patch = Circle((0, 0), 0.05)
557562
c = art3d.Patch3DCollection([patch], linewidths=3,
558-
edgecolor='C2', facecolor='C3')
563+
edgecolor='C2', facecolor='C3', alpha=0.7,
564+
depthshade=False)
559565

560566
ax_ref = fig_ref.add_subplot(projection='3d')
561567
ax_ref.add_collection3d(c)

0 commit comments

Comments
 (0)