I'm not sure.

In short, what savefig does is (when filename ending with "png" is
provided) is following.

def savefig(filename):
   f = open(filename,"wb")
   write_png(f)

I think there are two issue here.

1) write_png does not flush the file : this might be a bug or a
feature, I'm not sure.
2) f is somehow not flushed when savefig returns (which should happen
if file gets deleted). This only seems to happen in sage and this
seems to be the reason why savefig does not work.

As far as the second issues is concerned, I currently don't see
anything wrong in mpl's side. We may try to explicitly flush (or
close) the file after write_png, though.

I hope someone who is more knowledgeable than me take a look at this.
Meanwhile, I'll change the code to  explicitly close the opened file.

Regards,

-JJ





On Tue, Oct 6, 2009 at 1:44 PM,  <jason-s...@creativetrax.com> wrote:
> Jae-Joon Lee wrote:
>> I think this has nothing to do with dpi, but a file flushing issue.
>> Try something like below with sage (note that the code does not work
>> with svn version of matplotlib, i'll commit the fix soon).
>>
>> import matplotlib
>> matplotlib.use('Agg')
>> import matplotlib.pyplot as plt
>> fig=plt.figure()
>> plt.plot([1,2,3])
>> f = open("test.png", "wb")
>> plt.savefig(f, format="png", dpi=50)
>> f.flush()
>>
>> I'll report some more details later.
>>
>>
>
>
>
> This seems to have solved the problem on the two systems on which I've
> run experiments.  Now it makes perfect sense why I was always seeing a
> corrupt file size that was a multiple of 4K (e.g., 12K instead of 13K) :) .
>
> So just to confirm, is this a bug in matplotlib when using the
> plt.savefig(filename,dpi=72) form of calling savefig?
>
> Thanks,
>
> Jason
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
> http://p.sf.net/sfu/devconf
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to