savefig not deducing file format

Hi all,
I call savefig by passing to it a file-like object but it appears to not get the graphics format right:

f = open('not_a_pdf.pdf', 'w')
plot([1,2,3])
savefig(f)

but it produces a PNG image. Can anybody confirm this? I am on matplotlib 0.99.3

Cheers,

Giovanni

It has no way of deducing the file format from the file object.

You need to explicitly pass the format keyword to savefig, e.g.:

   savefig(f, format='pdf')

Mike

···

On 03/15/2011 07:11 AM, Giovanni Luca Ciampaglia wrote:

Hi all,
I call savefig by passing to it a file-like object but it appears to not
get the graphics format right:

f = open('not_a_pdf.pdf', 'w')
plot([1,2,3])
savefig(f)

but it produces a PNG image. Can anybody confirm this? I am on
matplotlib 0.99.3

Cheers,

Giovanni

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
   
--
Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

My fault, I didn't read the docstring properly. Thanks for both replies.

Best,

G

···

On 15/03/2011 13:51, Michael Droettboom wrote:

It has no way of deducing the file format from the file object.

You need to explicitly pass the format keyword to savefig, e.g.:

    savefig(f, format='pdf')

Mike

On 03/15/2011 07:11 AM, Giovanni Luca Ciampaglia wrote:

Hi all,
I call savefig by passing to it a file-like object but it appears to not
get the graphics format right:

f = open('not_a_pdf.pdf', 'w')
plot([1,2,3])
savefig(f)

but it produces a PNG image. Can anybody confirm this? I am on
matplotlib 0.99.3

Cheers,

Giovanni

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Inspect f.name?

Alan Isaac

···

On 3/15/2011 8:51 AM, Michael Droettboom wrote:

It has no way of deducing the file format from the file object.