Ситуация в таком коде (проверено на Python 3.12 с matplotlib 3.9.2):
Код: Выделить всё
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('qt5agg')
plt.ion()
f1 = plt.figure()
f1.gca().plot(1, 1, 'ro')
print(f1.number) # 1
f2 = plt.figure()
f2.gca().plot(1, 1, 'bo')
print(f2.number) # 2
plt.pause(5)
plt.close(f2)
f3 = plt.figure()
f3.gca().plot(1, 1, 'go')
print(f3.number) # also 2 !!!!
# now we want to save only the figures that have not been closed
# if not closed f1
f1.savefig('f1.png')
# if not closed f2 --- how to find, that f2 is closed and not execute the next line?
f2.savefig('f2.png')
# if not closed f3
f3.savefig('f3.png')
Подробнее здесь: https://stackoverflow.com/questions/792 ... een-closed