The default backend is specified in the
matplotlibrc file -- you could try changing it there.
It may also be that whatever environment you are running python in may already import matplotlib and specify the backend as part of the configuration. Also, some post suggest the following line may be needed:
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'