Skip to content

Commit 5a9f7cb

Browse files
committed
TST: Add tests for saving a figure after removing a widget axes
1 parent 1663e9a commit 5a9f7cb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import operator
44
from unittest import mock
55

6-
from matplotlib.backend_bases import MouseEvent
6+
from matplotlib.backend_bases import MouseEvent, DrawEvent
77
import matplotlib.colors as mcolors
88
import matplotlib.widgets as widgets
99
import matplotlib.pyplot as plt
@@ -1757,3 +1757,26 @@ def test_MultiCursor(horizOn, vertOn):
17571757
assert l.get_xdata() == (.5, .5)
17581758
for l in multi.hlines:
17591759
assert l.get_ydata() == (.25, .25)
1760+
1761+
1762+
def test_parent_axes_removal():
1763+
1764+
fig, (ax_radio, ax_checks) = plt.subplots(1, 2)
1765+
1766+
radio = widgets.RadioButtons(ax_radio, ['1', '2'], 0)
1767+
checks = widgets.CheckButtons(ax_checks, ['1', '2'], [True, False])
1768+
1769+
ax_checks.remove()
1770+
ax_radio.remove()
1771+
with io.BytesIO() as out:
1772+
# verify that saving does not raise
1773+
fig.savefig(out, format='raw')
1774+
1775+
# verify that this method which is triggered by a draw_event callback when
1776+
# blitting is enabled does not raise. Calling private methods is simpler
1777+
# than trying to force blitting to be enabled with Agg or use a GUI
1778+
# framework.
1779+
renderer = fig._get_renderer()
1780+
evt = DrawEvent('draw_event', fig.canvas, renderer)
1781+
radio._clear(evt)
1782+
checks._clear(evt)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy