Png files can handle transparency. So you could use this question Save plot to image file instead of displaying it using Matplotlib so as to save you graph as a png file. And if you want to turn all white pixel transparent, there's this other question : Using PIL to make all white pixels transparent?

3938