def to_png(self, filename, texstr, color='<STR_LIT>', dpi=<NUM_LIT>, fontsize=<NUM_LIT>):
rgba, depth = self.to_rgba(texstr, color=color, dpi=dpi, fontsize=fontsize)<EOL>numrows, numcols, tmp = rgba.shape<EOL>_png.write_png(rgba.tostring(), numcols, numrows, filename)<EOL>return depth<EOL>
Writes a tex expression to a PNG file.

Returns the offset of the baseline from the bottom of the
image in pixels.

*filename*
    A writable filename or fileobject

*texstr*
    A valid mathtext string, eg r'IQ: $\sigma_i=15$'

*color*
    A valid matplotlib color argument

*dpi*
    The dots-per-inch to render the text

*fontsize*
    The font size in points

Returns the offset of the baseline from the bottom of the
image in pixels.