File tree Expand file tree Collapse file tree
doc/api/next_api_changes/behavior Expand file tree Collapse file tree Original file line number Diff line number Diff 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
66calling these functions was maintained. To use the new functionality
77call as ``with plt.ioff(): ``
Original file line number Diff line number Diff 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__ ()
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
399398def ioff ():
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments