Python Forum

Full Version: How to continue code after .show() in matplotlib?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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()