10000 restore existing ion/ioff behavior + add test · matplotlib/matplotlib@0d93f1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d93f1b

Browse files
committed
restore existing ion/ioff behavior + add test
1 parent 80161d0 commit 0d93f1b

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

doc/api/next_api_changes/behavior/17371-IHI.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ ioff and ion can be used as context managers
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
``plt.ion()`` and ``plt.ioff()`` may now be used as context managers to create
5-
a context with interactive mode off, or on respectively. The old behavior of
5+
a context with interactive mode on, or off respectively. The old behavior of
66
calling these functions was maintained. To use the new functionality
77
call as ``with plt.ioff():``

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,36 +364,35 @@ def isinteractive():
364364
return matplotlib.is_interactive()
365365

366366

367-
class _ioff():
368-
def __call__(self):
367+
class _ioff:
368+
def __init__(self):
369+
self.wasinteractive = isinteractive()
369370
matplotlib.interactive(False)
370371
uninstall_repl_displayhook()
371372

372373
def __enter__(self):
373-
self.wasinteractive = isinteractive()
374-
self.__call__()
< 10000 code>374+
pass
375375

376376
def __exit__(self, exc_type, exc_value, traceback):
377377
if self.wasinteractive:
378378
matplotlib.interactive(True)
379379
install_repl_displayhook()
380-
del self.wasinteractive
381380

382381

383-
class _ion():
384-
def __call__(self):
382+
class _ion:
383+
def __init__(self):
384+
self.wasinteractive = isinteractive()
385385
matplotlib.interactive(True)
386386
install_repl_displayhook()
387387

388388
def __enter__(self):
389-
self.wasinteractive = isinteractive()
390-
self.__call__()
389+
pass
391390

392391
def __exit__(self, exc_type, exc_value, traceback):
393392
if not self.wasinteractive:
394393
matplotlib.interactive(False)
395394
uninstall_repl_displayhook()
396-
del self.wasinteractive
395+
self._used
397396

398397

399398
def ioff():

lib/matplotlib/tests/test_pyplot.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,29 @@ def test_nrows_error():
8383
plt.subplot(ncols=1)
8484

8585

86-
def test_ioff_context():
87-
mpl.interactive(True)
86+
def test_ioff():
87+
plt.ion()
88+
assert mpl.is_interactive()
8889
with plt.ioff():
8990
assert not mpl.is_interactive()
9091
assert mpl.is_interactive()
9192

92-
mpl.interactive(False)
93+
plt.ioff()
94+
assert not mpl.is_interactive()
9395
with plt.ioff():
9496
assert not mpl.is_interactive()
9597
assert not mpl.is_interactive()
9698

9799

98-
def test_ion_context():
99-
mpl.interactive(False)
100+
def test_ion():
101+
plt.ioff()
102+
assert not mpl.is_interactive()
100103
with plt.ion():
101104
assert mpl.is_interactive()
102105
assert not mpl.is_interactive()
103106

104-
mpl.interactive(True)
107+
plt.ion()
108+
assert mpl.is_interactive()
105109
with plt.ion():
106110
assert mpl.is_interactive()
107111
assert mpl.is_interactive()

0 commit comments

Comments
 (0)
0