Skip to content

Commit 5af57a7

Browse files
committed
ENH: add axisbelow option 'line', make it the default
1 parent c03262a commit 5af57a7

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from matplotlib.artist import allow_rasterization
3737

3838
from matplotlib.rcsetup import cycler
39+
from matplotlib.rcsetup import validate_axisbelow
3940

4041
rcParams = matplotlib.rcParams
4142

@@ -441,8 +442,9 @@ def __init__(self, fig, rect,
441442
*aspect* [ 'auto' | 'equal' | aspect_ratio ]
442443
*autoscale_on* [ *True* | *False* ] whether or not to
443444
autoscale the *viewlim*
444-
*axisbelow* draw the grids and ticks below the other
445-
artists
445+
*axisbelow* [ *True* | *False* | 'line'] draw the grids
446+
and ticks below or above most other artists,
447+
or below lines but above patches
446448
*cursor_props* a (*float*, *color*) tuple
447449
*figure* a :class:`~matplotlib.figure.Figure`
448450
instance
@@ -2308,12 +2310,16 @@ def draw(self, renderer=None, inframe=False):
23082310
artists.remove(spine)
23092311

23102312
if self.axison and not inframe:
2311-
if self._axisbelow:
2313+
if self._axisbelow == True:
23122314
self.xaxis.set_zorder(0.5)
23132315
self.yaxis.set_zorder(0.5)
2314-
else:
2316+
elif self._axisbelow == False:
23152317
self.xaxis.set_zorder(2.5)
23162318
self.yaxis.set_zorder(2.5)
2319+
else:
2320+
# above patches, below lines
2321+
self.xaxis.set_zorder(1.5)
2322+
self.yaxis.set_zorder(1.5)
23172323
else:
23182324
for _axis in self._get_axis_list():
23192325
artists.remove(_axis)
@@ -2413,9 +2419,9 @@ def set_axisbelow(self, b):
24132419
Set whether the axis ticks and gridlines are above or below most
24142420
artists
24152421
2416-
ACCEPTS: [ *True* | *False* ]
2422+
ACCEPTS: [ *True* | *False* | 'line' ]
24172423
"""
2418-
self._axisbelow = b
2424+
self._axisbelow = validate_axisbelow(b)
24192425
self.stale = True
24202426

24212427
@docstring.dedent_interpd

lib/matplotlib/rcsetup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ def validate_string_or_None(s):
175175
except ValueError:
176176
raise ValueError('Could not convert "%s" to string' % s)
177177

178+
def validate_axisbelow(s):
179+
try:
180+
return validate_bool(s)
181+
except ValueError:
182+
if isinstance(s, six.string_types):
183+
s = s.lower()
184+
if s.startswith('line'):
185+
return 'line'
186+
raise ValueError('%s cannot be interpreted as'
187+
' True, False, or "line"' % s)
188+
178189

179190
def validate_dpi(s):
180191
"""confirm s is string 'figure' or convert s to float or raise"""
@@ -981,7 +992,7 @@ def validate_animation_writer_path(p):
981992
'errorbar.capsize': [0, validate_float],
982993

983994
# axes props
984-
'axes.axisbelow': [False, validate_bool],
995+
'axes.axisbelow': ['line', validate_axisbelow],
985996
'axes.hold': [True, validate_bool],
986997
'axes.facecolor': ['w', validate_color], # background color; white
987998
'axes.edgecolor': ['k', validate_color], # edge color; black

0 commit comments

Comments
 (0)