It's slightly hackish, but would it be possible to do an "isinstance" 
check in savefig, and if the first arg is a PdfFile, set "format" to 
"pdf" automatically, and if "format" is set to something else raise an 
exception?  A little hackish because it doesn't necessarily scale to 
other formats easily, but it would prevent the user from shooting 
herself in the foot.

Mike

Jouni K. Seppänen wrote:
> I added support to the pdf backend for multipage pdf files. The current
> API (which I'm not entirely happy with) is that you create a PdfFile
> object, plot your figures, saving each one to the PdfFile object, and
> then close the object. The part I'm unhappy about is that because
> PdfFile is a file-like object - it has a write method - you can
> accidentally save your figure as a png into it and get a broken pdf
> file. You have to specify format='pdf' to savefig to avoid this.
>
> Here's an example:
>
> from matplotlib.backends.backend_pdf import PdfFile
>
> pdf = PdfFile('multipage_pdf.pdf')
>
> figure(...)
> # build your figure
> savefig(pdf, format='pdf')
>
> # repeat for all your figures
>
> pdf.close()
>
>
>   


------------------------------------------------------------------------------
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to