Search code examples
pythonmatplotlib

fignum_exists() not working on plt subplot


I am writing a program and have created the typical fig, ax = plt.subplot().

Now, I am in a loop and want to stop the program when the window is closed. When I do close the window, a new one opens instead.

I have not found a way to use not plt.fignum_exists().

What arguments do I need to pass this function to "trigger", when the window is closed?


Solution

  • I had a look at the code again and found out, how to make it work. What made it work was putting the plt.pause in front of the code block below.
    This does solve my problem, but I am not sure why.

    plt.pause(1 / frequenz)
    
    # Check if maximum length is reached
    if (all(len(data) >= zeitdauer * frequenz for data in
            temperature_data.values()) or not plt.fignum_exists(fig.number)):
        print("Program stopped")
        client.close()
        return