Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c232eba

Browse files
committed
Merge pull request #4768 from tacaswell/enh_axes.remove
ENH: add remove call back to axes
2 parents 61a869e + 555e03e commit c232eba

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
`ax.remove()` works as expected
2+
-------------------------------
3+
4+
As with artists added to as `Axes`, `Axes` can be
5+
removed from their figure via ``ax.remove()``

lib/matplotlib/figure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ def add_axes(self, *args, **kwargs):
908908

909909
self._axstack.add(key, a)
910910
self.sca(a)
911+
a._remove_method = lambda ax: self.delaxes(ax)
911912
self.stale = True
912913
return a
913914

@@ -996,6 +997,7 @@ def add_subplot(self, *args, **kwargs):
996997

997998
self._axstack.add(key, a)
998999
self.sca(a)
1000+
a._remove_method = lambda ax: self.delaxes(ax)
9991001
self.stale = True
10001002
return a
10011003

lib/matplotlib/tests/test_figure.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from matplotlib.externals import six
55
from matplotlib.externals.six.moves import xrange
66

7-
from nose.tools import assert_equal, assert_true, assert_raises
7+
from nose.tools import assert_equal, assert_true
88
from matplotlib.testing.decorators import image_comparison, cleanup
99
from matplotlib.axes import Axes
1010
import matplotlib.pyplot as plt
@@ -181,6 +181,16 @@ def test_set_fig_size():
181181
assert_equal(fig.get_figheight(), 3)
182182

183183

184+
@cleanup
185+
def test_axes_remove():
186+
fig, axes = plt.subplots(2, 2)
187+
axes[-1, -1].remove()
188+
for ax in axes.ravel()[:-1]:
189+
assert ax in fig.axes
190+
assert axes[-1, -1] not in fig.axes
191+
assert_equal(len(fig.axes), 3)
192+
193+
184194
if __name__ == "__main__":
185195
import nose
186196
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)