Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b316b9

Browse filesBrowse files
authored
Merge pull request #9094 from anntzer/axisbelow-zorder
MNT: axisbelow should just set zorder.
2 parents f4127b1 + 422f987 commit 4b316b9
Copy full SHA for 4b316b9

File tree

Expand file treeCollapse file tree

3 files changed

+30
-57
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+30
-57
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+20-19Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ def __init__(self, fig, rect,
455455
if self._position.width < 0 or self._position.height < 0:
456456
raise ValueError('Width and height specified must be non-negative')
457457
self._originalPosition = self._position.frozen()
458-
# self.set_axes(self)
459458
self.axes = self
460459
self._aspect = 'auto'
461460
self._adjustable = 'box'
@@ -479,7 +478,7 @@ def __init__(self, fig, rect,
479478
facecolor = rcParams['axes.facecolor']
480479
self._facecolor = facecolor
481480
self._frameon = frameon
482-
self._axisbelow = rcParams['axes.axisbelow']
481+
self.set_axisbelow(rcParams['axes.axisbelow'])
483482

484483
self._rasterization_zorder = None
485484
self._connected = {} # a dict from events to (id, func)
@@ -2530,18 +2529,7 @@ def draw(self, renderer=None, inframe=False):
25302529

25312530
self._update_title_position(renderer)
25322531

2533-
if self.axison and not inframe:
2534-
if self._axisbelow is True:
2535-
self.xaxis.set_zorder(0.5)
2536-
self.yaxis.set_zorder(0.5)
2537-
elif self._axisbelow is False:
2538-
self.xaxis.set_zorder(2.5)
2539-
self.yaxis.set_zorder(2.5)
2540-
else:
2541-
# 'line': above patches, below lines
2542-
self.xaxis.set_zorder(1.5)
2543-
self.yaxis.set_zorder(1.5)
2544-
else:
2532+
if not self.axison or inframe:
25452533
for _axis in self._get_axis_list():
25462534
artists.remove(_axis)
25472535

@@ -2613,9 +2601,7 @@ def get_renderer_cache(self):
26132601
# Axes rectangle characteristics
26142602

26152603
def get_frame_on(self):
2616-
"""
2617-
Get whether the axes rectangle patch is drawn.
2618-
"""
2604+
"""Get whether the axes rectangle patch is drawn."""
26192605
return self._frameon
26202606

26212607
def set_frame_on(self, b):
@@ -2637,13 +2623,26 @@ def get_axisbelow(self):
26372623

26382624
def set_axisbelow(self, b):
26392625
"""
2640-
Set whether axis ticks and gridlines are above or below most artists.
2626+
Set the zorder for the axes ticks and gridlines.
26412627
26422628
Parameters
26432629
----------
26442630
b : bool or 'line'
2631+
``True`` corresponds to a zorder of 0.5, ``False`` to a zorder of
2632+
2.5, and ``"line"`` to a zorder of 1.5.
2633+
26452634
"""
2646-
self._axisbelow = validate_axisbelow(b)
2635+
self._axisbelow = axisbelow = validate_axisbelow(b)
2636+
if axisbelow is True:
2637+
zorder = 0.5
2638+
elif axisbelow is False:
2639+
zorder = 2.5
2640+
elif axisbelow == "line":
2641+
zorder = 1.5
2642+
else:
2643+
raise ValueError("Unexpected axisbelow value")
2644+
for axis in self._get_axis_list():
2645+
axis.set_zorder(zorder)
26472646
self.stale = True
26482647

26492648
@docstring.dedent_interpd
@@ -2671,6 +2670,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):
26712670
26722671
%(Line2D)s
26732672
2673+
Note that the grid will be drawn according to the axes' zorder and not
2674+
its own.
26742675
"""
26752676
if len(kwargs):
26762677
b = True

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ def test_imshow_masked_interpolation():
786786
N = 20
787787
n = colors.Normalize(vmin=0, vmax=N*N-1)
788788

789-
# data = np.random.random((N, N))*N*N
790789
data = np.arange(N*N, dtype='float').reshape(N, N)
791790

792791
data[5, 5] = -1

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+10-37Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -272,28 +272,28 @@ def draw(self, renderer):
272272
renderer.eye = self.eye
273273
renderer.get_axis_position = self.get_axis_position
274274

275-
# Calculate projection of collections and zorder them
275+
# Calculate projection of collections and patches and zorder them.
276+
# Make sure they are drawn above the grids.
277+
zorder_offset = max(axis.get_zorder()
278+
for axis in self._get_axis_list()) + 1
276279
for i, col in enumerate(
277280
sorted(self.collections,
278281
key=lambda col: col.do_3d_projection(renderer),
279282
reverse=True)):
280-
col.zorder = i
281-
282-
# Calculate projection of patches and zorder them
283+
col.zorder = zorder_offset + i
283284
for i, patch in enumerate(
284285
sorted(self.patches,
285286
key=lambda patch: patch.do_3d_projection(renderer),
286287
reverse=True)):
287-
patch.zorder = i
288+
patch.zorder = zorder_offset + i
288289

289290
if self._axis3don:
290-
axes = (self.xaxis, self.yaxis, self.zaxis)
291291
# Draw panes first
292-
for ax in axes:
293-
ax.draw_pane(renderer)
292+
for axis in self._get_axis_list():
293+
axis.draw_pane(renderer)
294294
# Then axes
295-
for ax in axes:
296-
ax.draw(renderer)
295+
for axis in self._get_axis_list():
296+
axis.draw(renderer)
297297

298298
# Then rest
299299
super().draw(renderer)
@@ -1283,33 +1283,6 @@ def set_frame_on(self, b):
12831283
self._frameon = bool(b)
12841284
self.stale = True
12851285

1286-
def get_axisbelow(self):
1287-
"""
1288-
Get whether axis below is true or not.
1289-
1290-
For axes3d objects, this will always be *True*
1291-
1292-
.. versionadded :: 1.1.0
1293-
This function was added for completeness.
1294-
"""
1295-
return True
1296-
1297-
def set_axisbelow(self, b):
1298-
"""
1299-
Set whether axis ticks and gridlines are above or below most artists.
1300-
1301-
For axes3d objects, this will ignore any settings and just use *True*
1302-
1303-
.. versionadded :: 1.1.0
1304-
This function was added for completeness.
1305-
1306-
Parameters
1307-
----------
1308-
b : bool
1309-
"""
1310-
self._axisbelow = True
1311-
self.stale = True
1312-
13131286
def grid(self, b=True, **kwargs):
13141287
'''
13151288
Set / unset 3D grid.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.