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

Skip to content

FIX: be very paranoid about checking what the current canvas is #25573

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,3 +1740,14 @@ def test_MultiCursor(horizOn, vertOn):
assert l.get_xdata() == (.5, .5)
for l in multi.hlines:
assert l.get_ydata() == (.25, .25)


def test_parent_axes_removal():

fig, ax = plt.subplots(1, 1)

radio = widgets.RadioButtons(ax, ['1', '2'], 0)

ax.remove()
with io.BytesIO() as out:
fig.savefig(out, format='raw')
3 changes: 2 additions & 1 deletion lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ def _changed_canvas(self):
True if the canvas has been changed.

"""
return self.canvas is not self.ax.figure.canvas
# no canvas, something is very fishy
return self.canvas is not None and self.canvas is not self.canvas.figure.canvas


class AxesWidget(Widget):
Expand Down