@@ -333,16 +333,41 @@ def isinteractive():
333
333
return matplotlib .is_interactive ()
334
334
335
335
336
- def ioff ():
337
- """Turn the interactive mode off."""
338
- matplotlib .interactive (False )
339
- uninstall_repl_displayhook ()
336
+ class _ion_class ():
337
+ def __call__ (self ):
338
+ """Turn the interactive mode on."""
339
+ matplotlib .interactive (True )
340
+ install_repl_displayhook ()
340
341
342
+ def __enter__ (self ):
343
+ self .wasinteractive = isinteractive ()
344
+ self .__call__ ()
345
+
346
+ def __exit__ (self , exc_type , exc_value , traceback ):
347
+ if not self .wasinteractive :
348
+ matplotlib .interactive (False )
349
+ uninstall_repl_displayhook ()
350
+ del self .wasinteractive
351
+
352
+
353
+ class _ioff_class ():
354
+ def __call__ (self ):
355
+ """Turn the interactive mode off."""
356
+ matplotlib .interactive (False )
357
+ uninstall_repl_displayhook ()
358
+
359
+ def __enter__ (self ):
360
+ self .wasinteractive = isinteractive ()
361
+ self .__call__ ()
362
+
363
+ def __exit__ (self , exc_type , exc_value , traceback ):
364
+ if self .wasinteractive :
365
+ matplotlib .interactive (True )
366
+ install_repl_displayhook ()
367
+ del self .wasinteractive
341
368
342
- def ion ():
343
- """Turn the interactive mode on."""
344
- matplotlib .interactive (True )
345
- install_repl_displayhook ()
369
+ ioff = _ioff_class ()
370
+ ion = _ion_class ()
346
371
347
372
348
373
def pause (interval ):
0 commit comments