From ed02d72e92102b92072216cb3f05bc0b9ad4ccad Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 15 Nov 2017 20:49:56 -0500 Subject: [PATCH] FIX: treat `zorder=None` as falling back to the default closes #9785 --- lib/matplotlib/artist.py | 2 ++ lib/matplotlib/tests/test_artist.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 21edc744c7ad..9f18fc47fb58 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -885,6 +885,8 @@ def set_zorder(self, level): ACCEPTS: any number """ + if level is None: + level = self.__class__.zorder self.zorder = level self.pchanged() self.stale = True diff --git a/lib/matplotlib/tests/test_artist.py b/lib/matplotlib/tests/test_artist.py index 71b87e5af21a..e8f4f840536f 100644 --- a/lib/matplotlib/tests/test_artist.py +++ b/lib/matplotlib/tests/test_artist.py @@ -246,3 +246,13 @@ def test_setp(): sio = io.StringIO() plt.setp(lines1, 'zorder', file=sio) assert sio.getvalue() == ' zorder: any number \n' + + +def test_None_zorder(): + fig, ax = plt.subplots() + ln, = ax.plot(range(5), zorder=None) + assert ln.get_zorder() == mlines.Line2D.zorder + ln.set_zorder(123456) + assert ln.get_zorder() == 123456 + ln.set_zorder(None) + assert ln.get_zorder() == mlines.Line2D.zorder