@@ -49,7 +49,7 @@ class Axes3D(Axes):
4949 def __init__ (
5050 self , fig , rect = None , * args ,
5151 azim = - 60 , elev = 30 , sharez = None , proj_type = 'persp' ,
52- box_aspect = None ,
52+ box_aspect = None , computed_zorder = True ,
5353 ** kwargs ):
5454 """
5555 Parameters
@@ -66,6 +66,15 @@ def __init__(
6666 Other axes to share z-limits with.
6767 proj_type : {'persp', 'ortho'}
6868 The projection type, default 'persp'.
69+ computed_zorder : bool, default: True
70+ If True, the draw order is computed based on the average position
71+ of the `.Artist`s along the view direction.
72+ Set to False if you want to manually control the order in which
73+ Artists are drawn on top of each other using their *zorder*
74+ attribute. This can be used for fine-tuning if the automatic order
75+ does not produce the desired result. Note however, that a manual
76+ zorder will only be correct for a limited view angle. If the figure
77+ is rotated by the user, it will look wrong from certain angles.
6978 auto_add_to_figure : bool, default: True
7079 Prior to Matplotlib 3.4 Axes3D would add themselves
7180 to their host Figure on init. Other Axes class do not
@@ -79,11 +88,6 @@ def __init__(
7988 Other optional keyword arguments:
8089
8190 %(Axes3D_kwdoc)s
82-
83- Notes
84- -----
85- .. versionadded:: 1.2.1
86- The *sharez* parameter.
8791 """
8892
8993 if rect is None :
@@ -92,6 +96,7 @@ def __init__(
9296 self .initial_azim = azim
9397 self .initial_elev = elev
9498 self .set_proj_type (proj_type )
99+ self .computed_zorder = computed_zorder
95100
96101 self .xy_viewLim = Bbox .unit ()
97102 self .zz_viewLim = Bbox .unit ()
@@ -477,20 +482,26 @@ def do_3d_projection(artist):
477482 "%(since)s and will be removed %(removal)s." )
478483 return artist .do_3d_projection (renderer )
479484
480- # Calculate projection of collections and patches and zorder them.
481- # Make sure they are drawn above the grids.
482- zorder_offset = max (axis .get_zorder ()
483- for axis in self ._get_axis_list ()) + 1
484- for i , col in enumerate (
485- sorted (self .collections ,
486- key = do_3d_projection ,
487- reverse = True )):
488- col .zorder = zorder_offset + i
489- for i , patch in enumerate (
490- sorted (self .patches ,
491- key = do_3d_projection ,
492- reverse = True )):
493- patch .zorder = zorder_offset + i
485+ if self .computed_zorder :
486+ # Calculate projection of collections and patches and zorder
487+ # them. Make sure they are drawn above the grids.
488+ zorder_offset = max (axis .get_zorder ()
489+ for axis in self ._get_axis_list ()) + 1
490+ for i , col in enumerate (
491+ sorted (self .collections ,
492+ key = do_3d_projection ,
493+ reverse = True )):
494+ col .zorder = zorder_offset + i
495+ for i , patch in enumerate (
496+ sorted (self .patches ,
497+ key = do_3d_projection ,
498+ reverse = True )):
499+ patch .zorder = zorder_offset + i
500+ else :
501+ for col in self .collections :
502+ col .do_3d_projection ()
503+ for patch in self .patches :
504+ patch .do_3d_projection ()
494505
495506 if self ._axis3don :
496507 # Draw panes first
@@ -3505,6 +3516,7 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
35053516
35063517 stem3D = stem
35073518
3519+
35083520docstring .interpd .update (Axes3D_kwdoc = artist .kwdoc (Axes3D ))
35093521docstring .dedent_interpd (Axes3D .__init__ )
35103522
0 commit comments