1
plt.clf()
plt.figure().clear()
plt.close()
plt.close(fig)
plt.close('all') 

None of these lines which are solutions that I find in stack overflow like this one When to use cla(), clf() or close() for clearing a plot in matplotlib? work for me and I constantly get MemoryError: or tkinter.TclError: not enough free memory for image buffer I used them at the end of my loop which plotted figures.

for i in range(1000):
    fig, axs = plt.subplots(2,figsize=(12, 8), dpi=400, facecolor='w', edgecolor='k')
    axs[0].plot([0,1],[2,3])
    axs[1].plot([0,1],[2,3])
    plt.savefig("a.png")
    plt.clf()
    plt.figure().clear()
    plt.close()
    plt.close(fig)
    plt.close('all')  

What else can I do? And can you tell me is it a bug so it's gonna be debugged later which it doesn't seem to. so how my problem can be described (you may think why I'm asking you??!), cause there are really none possibilities that I had written those lines wrong or put it wrong where.

Red
  • 26,798
  • 7
  • 36
  • 58
Farhang Amaji
  • 742
  • 11
  • 24
  • who closed this, this problem is totally unsolved, if it is so, please give me solution cause all answers didn't work at all!!!! – Farhang Amaji Apr 28 '21 at 13:23
  • @BigBen Im familiar with that but it's not a specific problem its a general one. – Farhang Amaji Apr 28 '21 at 15:46
  • look at this https://stackoverflow.com/questions/8213522/when-to-use-cla-clf-or-close-for-clearing-a-plot-in-matplotlib it's same as mine and it's enough but the only difference is solutions worked for him – Farhang Amaji Apr 28 '21 at 15:52
  • there not much possibilities for this kind of problem so if you search here my question, you'd find all questions are minimal at this level – Farhang Amaji Apr 28 '21 at 15:54
  • just search my question with words memory error and matplotlib and plotting just that and these lines I just mentioned are just functions which do all work by themselves – Farhang Amaji Apr 28 '21 at 15:58
  • ok I change it but problem is the same – Farhang Amaji Apr 28 '21 at 15:58
  • @BigBen did you search my question? man this problem is either a bug or comes out of my faults so let people come and say "why didn't mention ... parameter" to me, you just don't close it. I really would need it in near future. – Farhang Amaji Apr 28 '21 at 19:47
  • I have no problem if someone tells me I should give more detail but because it's a mess of functions and don't give real useful information I prefer to keep it to minimal useful. – Farhang Amaji Apr 28 '21 at 19:51
  • this problem may not be same for everyone also because of versions of python packages – Farhang Amaji Apr 28 '21 at 19:53
  • never mind..... – Farhang Amaji Apr 28 '21 at 22:12
  • if Im doing(asking question wrong) please tell me what I should add?!!? – Farhang Amaji Apr 28 '21 at 22:14
  • thank you to anyone who reopened the question, now I'm listening to any further information may needed it and I have missed it. – Farhang Amaji Apr 29 '21 at 10:47

0 Answers0