Skip to content
Advertisement

matplotlib “fail to allocate bitmap” after some iterations

I can’t find a solution to avoid this crash.

I have cleaned up the attached code because it contains the issue and nothing else.

Regardless of the size of the image, the program crashes after 368 iterations.

I also tried what I could find in the forums but no solution found ( plt.close(‘all’), gc. collect()…. ).

JavaScript

Advertisement

Answer

According to this post, this is an issue with the TkAgg backend.

I was able to get it to work using:

JavaScript

I’ll have to beat on it some more to see if this is robust.

I saw the error message in this code:

http://search.cpan.org/src/NI-S/Tk-804.027/pTk/mTk/win/tkWinDraw.c

JavaScript

It is unclear to me why the bitmap from that C source code is null, but I’ve noticed that the Python memory usage keeps increasing with subsequent calls to create another plot/image/figure, regardless of whether one uses plt.close('all'), plt.clf(), gc.collect(), etc, so its failure to be created may have something to do with that. I don’t notice the same behaviour with, for example, the Agg backend.

One can read more about backend options in the docs, or checking the documentation for matplotlib.use():

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement