Python Forum
How to continue code after .show() in matplotlib? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to continue code after .show() in matplotlib? (/thread-20965.html)



How to continue code after .show() in matplotlib? - jasper100125 - Sep-08-2019

How can i continue my code thats written after .show() in the matplotlib library?
There needs to come an input from the user after the plot shown based of what the user sees in the plot, but i cant get my code to continue to run untill only after you have closed the plot's window by hand. Is there a way to keep it running?


RE: How to continue code after .show() in matplotlib? - luoheng - Sep-09-2019

You can use threading. Divide your code into plot part and other part.
from matplotlib import pyplot as plt
import threading

def yourFunc():
    result = input("your input: ")
    print(result)

def plot():
    x, y = [0, 1], [0, 1]
    plt.plot(x, y)
    plt.show()

def main():
    mthread = threading.Thread(target=yourFunc)
    mthread.start()
    plot()
    mthread.join()

main()