Skip to content

axisbelow should just set zorder. #9094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ def __init__(self, fig, rect,
if self._position.width < 0 or self._position.height < 0:
raise ValueError('Width and height specified must be non-negative')
self._originalPosition = self._position.frozen()
# self.set_axes(self)
self.axes = self
self._aspect = 'auto'
self._adjustable = 'box'
Expand All @@ -501,7 +500,7 @@ def __init__(self, fig, rect,
facecolor = rcParams['axes.facecolor']
self._facecolor = facecolor
self._frameon = frameon
self._axisbelow = rcParams['axes.axisbelow']
self.set_axisbelow(rcParams['axes.axisbelow'])

self._rasterization_zorder = None
self._connected = {} # a dict from events to (id, func)
Expand Down Expand Up @@ -2537,18 +2536,7 @@ def draw(self, renderer=None, inframe=False):

self._update_title_position(renderer)

if self.axison and not inframe:
if self._axisbelow is True:
self.xaxis.set_zorder(0.5)
self.yaxis.set_zorder(0.5)
elif self._axisbelow is False:
self.xaxis.set_zorder(2.5)
self.yaxis.set_zorder(2.5)
else:
# 'line': above patches, below lines
self.xaxis.set_zorder(1.5)
self.yaxis.set_zorder(1.5)
else:
if not self.axison or inframe:
for _axis in self._get_axis_list():
artists.remove(_axis)

Expand Down Expand Up @@ -2620,9 +2608,7 @@ def get_renderer_cache(self):
# Axes rectangle characteristics

def get_frame_on(self):
"""
Get whether the axes rectangle patch is drawn.
"""
"""Get whether the axes rectangle patch is drawn."""
return self._frameon

def set_frame_on(self, b):
Expand All @@ -2644,13 +2630,26 @@ def get_axisbelow(self):

def set_axisbelow(self, b):
"""
Set whether axis ticks and gridlines are above or below most artists.
Set the zorder for the axes ticks and gridlines.

Parameters
----------
b : bool or 'line'
``True`` corresponds to a zorder of 0.5, ``False`` to a zorder of
2.5, and ``"line"`` to a zorder of 1.5.

"""
self._axisbelow = validate_axisbelow(b)
self._axisbelow = axisbelow = validate_axisbelow(b)
if axisbelow is True:
zorder = 0.5
elif axisbelow is False:
zorder = 2.5
elif axisbelow == "line":
zorder = 1.5
else:
raise ValueError("Unexpected axisbelow value")
for axis in self._get_axis_list():
axis.set_zorder(zorder)
self.stale = True

@docstring.dedent_interpd
Expand Down Expand Up @@ -2678,6 +2677,8 @@ def grid(self, b=None, which='major', axis='both', **kwargs):

%(Line2D)s

Note that the grid will be drawn according to the axes' zorder and not
its own.
"""
if len(kwargs):
b = True
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,6 @@ def test_imshow_masked_interpolation():
N = 20
n = colors.Normalize(vmin=0, vmax=N*N-1)

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

data[5, 5] = -1
Expand Down
47 changes: 10 additions & 37 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,28 @@ def draw(self, renderer):
renderer.eye = self.eye
renderer.get_axis_position = self.get_axis_position

# Calculate projection of collections and zorder them
# Calculate projection of collections and patches and zorder them.
# Make sure they are drawn above the grids.
zorder_offset = max(axis.get_zorder()
for axis in self._get_axis_list()) + 1
for i, col in enumerate(
sorted(self.collections,
key=lambda col: col.do_3d_projection(renderer),
reverse=True)):
col.zorder = i

# Calculate projection of patches and zorder them
col.zorder = zorder_offset + i
for i, patch in enumerate(
sorted(self.patches,
key=lambda patch: patch.do_3d_projection(renderer),
reverse=True)):
patch.zorder = i
patch.zorder = zorder_offset + i

if self._axis3don:
axes = (self.xaxis, self.yaxis, self.zaxis)
# Draw panes first
for ax in axes:
ax.draw_pane(renderer)
for axis in self._get_axis_list():
axis.draw_pane(renderer)
# Then axes
for ax in axes:
ax.draw(renderer)
for axis in self._get_axis_list():
axis.draw(renderer)

# Then rest
super().draw(renderer)
Expand Down Expand Up @@ -1283,33 +1283,6 @@ def set_frame_on(self, b):
self._frameon = bool(b)
self.stale = True

def get_axisbelow(self):
"""
Get whether axis below is true or not.

For axes3d objects, this will always be *True*

.. versionadded :: 1.1.0
This function was added for completeness.
"""
return True

def set_axisbelow(self, b):
"""
Set whether axis ticks and gridlines are above or below most artists.

For axes3d objects, this will ignore any settings and just use *True*

.. versionadded :: 1.1.0
This function was added for completeness.

Parameters
----------
b : bool
"""
self._axisbelow = True
self.stale = True

def grid(self, b=True, **kwargs):
'''
Set / unset 3D grid.
Expand Down