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

Skip to content

ENH: add remove call back to axes #4768

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 23, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
ENH: add remove call back to axes
ax.remove() now works as expected
  • Loading branch information
tacaswell committed Jul 23, 2015
commit 56d256111c7a2322943abc69a6f4e8401893a0d5
2 changes: 2 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ def add_axes(self, *args, **kwargs):

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
self.stale = True
return a

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

self._axstack.add(key, a)
self.sca(a)
a._remove_method = lambda ax: self.delaxes(ax)
self.stale = True
return a

Expand Down
12 changes: 11 additions & 1 deletion lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from matplotlib.externals import six
from matplotlib.externals.six.moves import xrange

from nose.tools import assert_equal, assert_true, assert_raises
from nose.tools import assert_equal, assert_true
from matplotlib.testing.decorators import image_comparison, cleanup
from matplotlib.axes import Axes
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -181,6 +181,16 @@ def test_set_fig_size():
assert_equal(fig.get_figheight(), 3)


@cleanup
def test_axes_remove():
fig, axes = plt.subplots(2, 2)
axes[-1, -1].remove()
for ax in axes.ravel()[:-1]:
assert ax in fig.axes
assert axes[-1, -1] not in fig.axes
assert_equal(len(fig.axes), 3)


if __name__ == "__main__":
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)