Q:

Matplotlib figure doesn't render correctly if show not called

So I'm using matlibplot with Python 2.7.5 :: Anaconda 1.7.0 (64-bit)
The only uncommented lines in my matlibplot.rc file are:  
figure.figsize   : 10, 5    # figure size in inches
figure.dpi       : 80      # figure dots per inch  
figure.facecolor : 1   # figure facecolor; 0.75 is scalar gray  
savefig.dpi         : 80      # figure dots per inch  
savefig.facecolor   : white    # figure facecolor when saving  

If I call:  
plt.savefig(name, bbox_inches=0)  
plt.show()  

everything works fine  
Output from show:

Output from savefig:

However, if I simply comment out the show line the same file looks like this:

What's going on???  How can I fix this?

A:

It's likely that previous figures are being overlaid on the current figure, especially if you have hold on.
Two simple ways to fix this:
Toggle hold before plotting to clear the graph:
pylab.hold(False) # clears graph
pylab.hold(True) # restores to state you want

Or explicitly clear the graph after saving:
pylab.save(...)
pylab.close()

The reason you don't see this behaviour with show is that there is an implicit close called when you close the figure which appears.

