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 51f8468

Browse filesBrowse files
committed
axisbelow should just set zorder.
1 parent a0994d3 commit 51f8468
Copy full SHA for 51f8468

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
@@ -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

‎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.