`
import matplotlib.pyplot as plt
import pandas as pd
l1 = [1,2,3,4]
l2 = [2,4,6,8]
fig = plt.figure()
def func():
plt.pause(1)
plt.plot(l1,l2)
plt.draw()
plt.pause(1)
input("press any key to continue...")
plt.close(fig)
plt.pause(1)
while True:
func()
plt.pause(1)
`
This is the modified one:
`
import matplotlib.pyplot as plt
import pandas as pd
l1 = [1,2,3,4]
l2 = [2,4,6,8]
fig = plt.figure()
a = 1
def func(num):
input(f"the {num}th window is not opened yet")
plt.pause(1)
plt.plot(l1,l2)
plt.draw()
print(f"the {num}th window is opened")
plt.pause(1)
input("press any key to continue...")
plt.close(fig)
plt.pause(1)
print(f"the {num}th window is closed")
while True:
func(a)
plt.pause(1)
a+=1
`
If I don't use while True loop, it stops running as I press any key and that was my intention. However, if I run this code with while True loop, the figure window doesn't close even though I press any key or x button in the upper left. I think it is due to while True. I have no idea how to solve this problem, keeping while True. Please help me!
- modified: I could see an opened window when "The 2th window is not opened yet" input message came out. Probably, the window would be the one from the first time of the loop, since the second window wasn't opened at that time. Why was the first window still there? I used plt.close() to close the window.