Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug summary
In interactive mode (plt.ion()
), creating a plot and then immediately having a call toinput()
causes the plot to not display until after the call toinput()
has finished. Specifically, only an empty window is created initially, and it is not populated until after the call toinput()
is finished.
Code for reproduction
frommatplotlibimportpyplotaspltx= [0,1]y= [2,3]plt.ion()# We expect the call to plt.plot() to create a figure since we're in interactive mode:plt.plot(x,y);input("Some input: ")# This line has the same effect as the above one:plt.plot(x,y);plt.ioff();plt.show(block=False);input("Some input: ")
Actual outcome
Matplotlib produces the following empty window:
Attempting to interact with this window tends to make Python unhappy.
The main terminal is pefectly responsive, and the input prompt can be typed in.
Only after theinput()
call is complete will the plot actually display as intended, even with callingplt.ioff()
andplt.show()
afterwards.
Expected outcome
Ideally, the plot would update and display whileinput()
is waiting for user input.
Additional information
Tested on several versions back; this issue also occurs on version 3.7.0, but not on versions 3.6.0 to 3.6.3.
Some additional info:
- This issue happens in scripts and in the interactive terminal (ran in IPython 7.34.0), but not in Jupyter notebooks (tested the same snippet and it works the expected way).
- If a plot is already displaying in interactive mode and this happens, the plot will just not update until after
input()
is finished - This also happens if the creation of the plot and the call to
input
are more widely-separated; callingtime.sleep()
in between does not help. - Turning off interactive mode before calling
input
does not fix the issue, nor does callingplt.show()
withblock=False
(f.e. the lineplt.plot(x, y); plt.ioff(); plt.show(block=False); input("Some input: ")
runs exactly the same)
Operating system
Windows 10
Matplotlib Version
3.7.1
Matplotlib Backend
TkAgg
Python version
3.9.12
Jupyter version
6.4.8
Installation
pip