Skip to content

Commit

Permalink
FIX: account for None in Line2D.axes setter
Browse files Browse the repository at this point in the history
  • Loading branch information
tacaswell committed Aug 20, 2015
1 parent 6b9ff9c commit 344abbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 8 additions & 7 deletions lib/matplotlib/lines.py
Expand Up @@ -568,13 +568,14 @@ def get_window_extent(self, renderer):
def axes(self, ax):
# call the set method from the base-class property
Artist.axes.fset(self, ax)
# connect unit-related callbacks
if ax.xaxis is not None:
self._xcid = ax.xaxis.callbacks.connect('units',
self.recache_always)
if ax.yaxis is not None:
self._ycid = ax.yaxis.callbacks.connect('units',
self.recache_always)
if ax is not None:
# connect unit-related callbacks
if ax.xaxis is not None:
self._xcid = ax.xaxis.callbacks.connect('units',
self.recache_always)
if ax.yaxis is not None:
self._ycid = ax.yaxis.callbacks.connect('units',
self.recache_always)

def set_data(self, *args):
"""
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/tests/test_artist.py
Expand Up @@ -150,21 +150,27 @@ def test_cull_markers():
def test_remove():
fig, ax = plt.subplots()
im = ax.imshow(np.arange(36).reshape(6, 6))
ln, = ax.plot(range(5))

assert_true(fig.stale)
assert_true(ax.stale)

fig.canvas.draw()
assert_false(fig.stale)
assert_false(ax.stale)
assert_false(ln.stale)

assert_true(im in ax.mouseover_set)
assert_true(ln not in ax.mouseover_set)
assert_true(im.axes is ax)

im.remove()
ln.remove()

for art in [im, ln]:
assert_true(art.axes is None)
assert_true(art.figure is None)

assert_true(im.axes is None)
assert_true(im.figure is None)
assert_true(im not in ax.mouseover_set)
assert_true(fig.stale)
assert_true(ax.stale)
Expand Down

0 comments on commit 344abbf

Please sign in to comment.