@@ -477,7 +477,6 @@ def __init__(self, fig, rect,
477477 if self ._position .width < 0 or self ._position .height < 0 :
478478 raise ValueError ('Width and height specified must be non-negative' )
479479 self ._originalPosition = self ._position .frozen ()
480- # self.set_axes(self)
481480 self .axes = self
482481 self ._aspect = 'auto'
483482 self ._adjustable = 'box'
@@ -501,7 +500,7 @@ def __init__(self, fig, rect,
501500 facecolor = rcParams ['axes.facecolor' ]
502501 self ._facecolor = facecolor
503502 self ._frameon = frameon
504- self ._axisbelow = rcParams ['axes.axisbelow' ]
503+ self .set_axisbelow ( rcParams ['axes.axisbelow' ])
505504
506505 self ._rasterization_zorder = None
507506 self ._connected = {} # a dict from events to (id, func)
@@ -2537,18 +2536,7 @@ def draw(self, renderer=None, inframe=False):
25372536
25382537 self ._update_title_position (renderer )
25392538
2540- if self .axison and not inframe :
2541- if self ._axisbelow is True :
2542- self .xaxis .set_zorder (0.5 )
2543- self .yaxis .set_zorder (0.5 )
2544- elif self ._axisbelow is False :
2545- self .xaxis .set_zorder (2.5 )
2546- self .yaxis .set_zorder (2.5 )
2547- else :
2548- # 'line': above patches, below lines
2549- self .xaxis .set_zorder (1.5 )
2550- self .yaxis .set_zorder (1.5 )
2551- else :
2539+ if not self .axison or inframe :
25522540 for _axis in self ._get_axis_list ():
25532541 artists .remove (_axis )
25542542
@@ -2620,9 +2608,7 @@ def get_renderer_cache(self):
26202608 # Axes rectangle characteristics
26212609
26222610 def get_frame_on (self ):
2623- """
2624- Get whether the axes rectangle patch is drawn.
2625- """
2611+ """Get whether the axes rectangle patch is drawn."""
26262612 return self ._frameon
26272613
26282614 def set_frame_on (self , b ):
@@ -2644,13 +2630,26 @@ def get_axisbelow(self):
26442630
26452631 def set_axisbelow (self , b ):
26462632 """
2647- Set whether axis ticks and gridlines are above or below most artists.
2633+ Set the zorder for the axes ticks and gridlines.
2634+
2635+ ``True`` corresponds to a zorder of 0.5, ``False`` to a zorder of 2.5,
2636+ and ``"line"`` to a zorder of 1.5.
26482637
26492638 Parameters
26502639 ----------
26512640 b : bool or 'line'
26522641 """
2653- self ._axisbelow = validate_axisbelow (b )
2642+ self ._axisbelow = axisbelow = validate_axisbelow (b )
2643+ if axisbelow is True :
2644+ zorder = 0.5
2645+ elif axisbelow is False :
2646+ zorder = 2.5
2647+ elif axisbelow == "line" :
2648+ zorder = 1.5
2649+ else :
2650+ raise ValueError ("Unexpected axisbelow value" )
2651+ for axis in self ._get_axis_list ():
2652+ axis .set_zorder (zorder )
26542653 self .stale = True
26552654
26562655 @docstring .dedent_interpd
@@ -2678,6 +2677,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26782677
26792678 %(Line2D)s
26802679
2680+ Note that the grid will be drawn according to the axes' zorder and not
2681+ its own.
26812682 """
26822683 if len (kwargs ):
26832684 b = True
0 commit comments