How can I close the figure window in matplotlib?

Viewed 22
import matplotlib.pyplot as plt
import pandas as pd
l1 = [1,2,3,4]
l2 = [2,4,6,8]


def func():
    fig,ax = plt.subplots()
    plt.pause(1)
    plt.plot(l1,l2)
    plt.draw()
    plt.pause(1)
    input("press any key to continue...")
    plt.close()
    plt.pause(1)

while True:
    func()
    plt.pause(1)

I want to open and close the figure window every time in the loop. I don't want to see the window when it closes. I thought plt.close() could work this way, but it doesn't in the while True loop. The window doesn't close even when I click the x button in the upper left. I have no idea how to solve this problem. Please help me out! ToT

0 Answers
Related