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 56d2561

Browse filesBrowse files
committed
ENH: add remove call back to axes
ax.remove() now works as expected
1 parent b1b4fb8 commit 56d2561
Copy full SHA for 56d2561

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+11-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.