Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ea74eff

Browse files
committed
add documentation warning against using return value of ion/ioff
1 parent afe8d07 commit ea74eff

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

lib/matplotlib/pyplot.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def isinteractive():
364364
return matplotlib.is_interactive()
365365

366366

367-
class _ioff:
367+
class _IoffContext:
368368
"""
369369
Context manager for `.ioff`.
370370
@@ -387,7 +387,7 @@ def __exit__(self, exc_type, exc_value, traceback):
387387
install_repl_displayhook()
388388

389389

390-
class _ion:
390+
class _IonContext:
391391
"""
392392
Context manager for `.ion`.
393393
@@ -426,20 +426,23 @@ def ioff():
426426
-----
427427
For a temporary change, this can be used as a context manager::
428428
429+
# if interactive mode is on
430+
# then figures will be shown on creation
431+
plt.ion()
432+
# This figure will be shown immediately
433+
fig = plt.figure()
434+
429435
with plt.ioff():
430436
# interactive mode will be off
431437
# figures will not automatically be shown
432-
fig1 = plt.figure()
438+
fig2 = plt.figure()
433439
# ...
434440
435-
# This figure will be shown immediately
436-
fig2 = plt.figure()
437-
438-
The return value of `plt.ioff` is necessary to make the function work
439-
as a context manager. It is not intended to be stored or accessed
440-
by the user.
441+
To enable usage as a context manager, this function returns an
442+
``_IoffContext`` object. The return value is not intended to be stored
443+
or accessed by the user.
441444
"""
442-
return _ioff()
445+
return _IoffContext()
443446

444447

445448
def ion():
@@ -448,7 +451,7 @@ def ion():
448451
449452
See Also
450453
--------
451-
ion : enable interactive mode
454+
ioff : disable interactive mode
452455
isinteractive : query current state
453456
454457
show : show windows (and maybe block)
@@ -462,19 +465,19 @@ def ion():
462465
# then figures will not be shown on creation
463466
plt.ioff()
464467
# This figure will not be shown immediately
465-
fig2 = plt.figure()
468+
fig = plt.figure()
466469
467470
with plt.ion():
468471
# interactive mode will be on
469472
# figures will automatically be shown
470-
fig1 = plt.figure()
473+
fig2 = plt.figure()
471474
# ...
472475
473-
The return value of `plt.ion` is necessary to make the function work
474-
as a context manager. It is not intended to be stored or accessed
475-
by the user.
476+
To enable usage as a context manager, this function returns an
477+
``_IonContext`` object. The return value is not intended to be stored
478+
or accessed by the user.
476479
"""
477-
return _ion()
480+
return _IonContext()
478481

479482

480483
def pause(interval):

0 commit comments

Comments
 (0)