Christopher Bull bio photo

Christopher Bull

Aspiring Oceanographer at the British Antarctic Survey. Big data python enthusiast. Outdoor adventurer.

Email Twitter Github

I wanted to make a movie, the plan was to use Matplotlib to make the frames and then stitch them together using ffmpeg. The problem I had was that I’d make about 1000 frames and then it would crash with this rather obtuse error:

RuntimeError: Could not open facefile /share/apps/python/2.7.2/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf; Cannot_Open_Resource

I suspected it was leaking memory and running the script on a bigger machine confirmed it. It turns out you have to be explicit rather than implicit when defining your figure/axes. Bit of annoying bug really. To better explain, basically I had:

    for loop_through_picture_maker:
        plt.close('all')
    
        #code that produces a plot using implicit figure and axes
    
        plt.close()

And what I needed was:

    fig=plt.figure()
    for loop_through_picture_maker:
        ax=fig.add_subplot(111)
    
        #code that produces a plot using explicit figure and axes
    
        fig.clf()
        del ax

My thanks to Jean-François Exbrayat for pointing out the bug.

NB: this was with Matplotlib 1.1.0.

In category: python