Jae-Joon Lee wrote:

Jae-Joon Lee wrote:

As one of who never used Sage, I don't think I'll be any help here.

Anyhow, can you tell us what kind of backed is used by default in the

two environment? I mean the type of the canvas that is initially

created.

Thanks for following up on this. Is there an easy way to ask matplotlib

what its default canvas is (i.e., what canvas pyplot will use for savefig)?

I believe it's probably using the FigureCanvasAgg canvas, but I'm not sure.

Since I've reproduced the problem with pure matplotlib code, I'm not sure

where the canvas is set up and initialized.

In [17]: fig = plt.figure()

In [18]: print type(fig.canvas)

<class 'matplotlib.backends.backend_gtkagg.FigureCanvasGTKAgg'>

See if matplotlib session and sage session uses different backend.

It seems to be some dpi issue, but MPL supposed to handle this correctly.

I guess it also works fine if the figure is initially created with the

matching dpi as the savefig (72),?

I'm not sure what you're asking here or how to test your assumption. I

posted the code that gave the problem in a Sage session, but worked fine in

a normal python session. I also saw the problem (cut-off bottom in firefox,

which looked like a transparent bottom portion of the figure in gimp) with

varying amounts when I specified other dpi values. Is there something I can

insert into my script to test what you're asking?

plt.figure takes dpi parameter. This is the dpi of the figure instance

(not the output). Set this to same value as one you use for savefig.

Again, I'm really puzzled by this. We are using just pure matplotlib, and

yet, there seems to be something in the Sage configuration or environment or

something that is causing pure matplotlib code to generate these erroneous

figures, but the exact same installation of matplotlib, when run under

python, generates perfectly fine figures.

I do not have any clue either. However, one possibility I can think of

is that it is a bug in certain backend whose savefig command does not

take care of changing dpi correctly. If it turns out that the sage

session and ipython session uses a same backend, then, I have no idea.

I hope some other developer who uses sage take a look at this.

I ran some more tests, this time on sage.math.washington.edu, which is a 64-bit Ubuntu system. This time, instead of errors, all I saw were zero-length files! (i.e., the file was there, but it was completely empty, i.e., zero bytes). I consistently produced a zero-length file the first time I used the dpi keyword argument to savefig. If I called savefig again, the correct figure was saved to the file. Any ideas about what in the world could be going on here? The logs of my trials are below.

Using Sage's copy of python (2.6.2), the code printed out the exact same values for fig.canvas and fig.dpi each time, but there were no erroneous figures (i.e., all of the figures were saved to images correctly the first time savefig was called and the dpi was specified in savefig).

Thanks,

Jason

<new Sage session>

sage: import matplotlib.pyplot as plt;import numpy

sage: fig=plt.figure()

sage: print fig.canvas

<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x4ad8440>

sage: print fig.dpi

80

sage: plt.plot(numpy.arange(0,1.1,0.01))

[<matplotlib.lines.Line2D object at 0x51275d0>]

sage: plt.savefig('foo.png',dpi=72) # zero-length file generated

sage: plt.savefig('foo.png',dpi=72) # correct figure generated

<new Sage session>

sage: import matplotlib.pyplot as plt;import numpy

sage: fig=plt.figure(dpi=72)

sage: print fig.canvas

<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x4ad94d0>

sage: print fig.dpi

72

sage: plt.plot(numpy.arange(0,1.1,0.01))

[<matplotlib.lines.Line2D object at 0x51285d0>]

sage: plt.savefig('foo.png',dpi=72) # zero-length file generated

sage: plt.savefig('foo.png',dpi=72) # correct figure generated

<new Sage Session>

sage: import matplotlib.pyplot as plt;import numpy

sage: fig=plt.figure()

sage: print fig.canvas

<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x4ad7440>

sage: print fig.dpi

80

sage: plt.plot(numpy.arange(0,1.1,0.01))

[<matplotlib.lines.Line2D object at 0x51305d0>]

sage: plt.savefig('foo.png',dpi=80) # zero-length file generated

sage: plt.savefig('foo.png',dpi=80) # correct figure generated

<new Sage Session>

sage: import matplotlib.pyplot as plt;import numpy

sage: fig=plt.figure(dpi=72)

sage: print fig.canvas

<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x4ad94d0>

sage: print fig.dpi

72

sage: plt.plot(numpy.arange(0,1.1,0.01))

[<matplotlib.lines.Line2D object at 0x51325d0>]

sage: plt.savefig('foo.png') # correct figure generated

<new Sage session>

sage: import matplotlib.pyplot as plt;import numpy

sage: fig=plt.figure()

sage: print fig.canvas

<matplotlib.backends.backend_agg.FigureCanvasAgg instance at 0x4ad8440>

sage: print fig.dpi

80

sage: plt.plot(numpy.arange(0,1.1,0.01))

[<matplotlib.lines.Line2D object at 0x51275d0>]

sage: plt.savefig('foo.png') # correct figure generated

## ···

On Mon, Oct 5, 2009 at 10:25 PM, <jason-sage@...2130...> wrote: