Matplotlib waitforkeypress() doesn't work

Answered

Hello,

I'm running v2019.2 (PY-192.6817.19) and a simple script like:

import matplotlib.pyplot as plt

plt.ion() #doesn't matter if this is omitted
plt.plot(0.1, 0.1, "go")
plt.plot(0.2, 0.2, "bo")
plt.xlim(0,1)
plt.ylim(0,1)
plt.waitforkeypress()

should draw a graph and wait for me to press a button. It does draw a graph but won't accept any input and so the script just hangs.

I have enabled "Emulate Terminal in Output Console" to no avail.

How do I fix this?

Thanks!

1 comment
Comment actions Permalink

Unfortunately, it's not supported at the moment.

Please vote for https://youtrack.jetbrains.com/issue/PY-29311

A workaround is to use another backend. For example:

import matplotlib.pyplot as plt
import matplotlib

matplotlib.use('TkAgg')

plt.ion() # doesn't matter if this is omitted
plt.plot(0.1, 0.1, "go")
plt.plot(0.2, 0.2, "bo")
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.waitforbuttonpress()
0

Please sign in to leave a comment.