File tree Expand file tree Collapse file tree 3 files changed +20
-17
lines changed
doc/api/next_api_changes/behavior Expand file tree Collapse file tree 3 files changed +20
-17
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ ioff and ion can be used as context managers
2
2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
3
4
4
``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
6
6
calling these functions was maintained. To use the new functionality
7
7
call as ``with plt.ioff(): ``
Original file line number Diff line number Diff line change @@ -364,36 +364,35 @@ def isinteractive():
364
364
return matplotlib .is_interactive ()
365
365
366
366
367
- class _ioff ():
368
- def __call__ (self ):
367
+ class _ioff :
368
+ def __init__ (self ):
369
+ self .wasinteractive = isinteractive ()
369
370
matplotlib .interactive (False )
370
371
uninstall_repl_displayhook ()
371
372
372
373
def __enter__ (self ):
373
- self .wasinteractive = isinteractive ()
374
- self .__call__ ()
<
10000
code> 374
+ pass
375
375
376
376
def __exit__ (self , exc_type , exc_value , traceback ):
377
377
if self .wasinteractive :
378
378
matplotlib .interactive (True )
379
379
install_repl_displayhook ()
380
- del self .wasinteractive
381
380
382
381
383
- class _ion ():
384
- def __call__ (self ):
382
+ class _ion :
383
+ def __init__ (self ):
384
+ self .wasinteractive = isinteractive ()
385
385
matplotlib .interactive (True )
386
386
install_repl_displayhook ()
387
387
388
388
def __enter__ (self ):
389
- self .wasinteractive = isinteractive ()
390
- self .__call__ ()
389
+ pass
391
390
392
391
def __exit__ (self , exc_type , exc_value , traceback ):
393
392
if not self .wasinteractive :
394
393
matplotlib .interactive (False )
395
394
uninstall_repl_displayhook ()
396
- del self .wasinteractive
395
+ self ._used
397
396
398
397
399
398
def ioff ():
Original file line number Diff line number Diff line change @@ -83,25 +83,29 @@ def test_nrows_error():
83
83
plt .subplot (ncols = 1 )
84
84
85
85
86
- def test_ioff_context ():
87
- mpl .interactive (True )
86
+ def test_ioff ():
87
+ plt .ion ()
88
+ assert mpl .is_interactive ()
88
89
with plt .ioff ():
89
90
assert not mpl .is_interactive ()
90
91
assert mpl .is_interactive ()
91
92
92
- mpl .interactive (False )
93
+ plt .ioff ()
94
+ assert not mpl .is_interactive ()
93
95
with plt .ioff ():
94
96
assert not mpl .is_interactive ()
95
97
assert not mpl .is_interactive ()
96
98
97
99
98
- def test_ion_context ():
99
- mpl .interactive (False )
100
+ def test_ion ():
101
+ plt .ioff ()
102
+ assert not mpl .is_interactive ()
100
103
with plt .ion ():
101
104
assert mpl .is_interactive ()
102
105
assert not mpl .is_interactive ()
103
106
104
- mpl .interactive (True )
107
+ plt .ion ()
108
+ assert mpl .is_interactive ()
105
109
with plt .ion ():
106
110
assert mpl .is_interactive ()
107
111
assert mpl .is_interactive ()
You can’t perform that action at this time.
0 commit comments