From: Hans Georg Schaathun on
Admittedly not the strongest reason, but yet an important one,
for switching from Matlab to python/numpy/scipy/matplotlib,
is that Matlab is very cumbersome to run in batch.

Now I discover that some of the matplotlib.pyplot functions
(incl. plot and contour) insist on opening an X11 window
(just like Matlab does). I would have preferred just to create
the plot straight on file. The extra window is a nuisance on my
laptop, it is deep-felt pain if I try to run it remotely. It fails
completely if I run it without any display at all.

Oddly, the bar() function does not open a window by default.
I was very happy with that. It works exactly the way I want.
(Why isn't pyplot more consistent?)

Is there something I have missed? Is it possible to create
standard 2D plots and contour plots without a display, writing
the graphics straight into a PDF file?

I'll be grateful for any pointers and ideas,
:-- George
From: Emile van Sebille on
On 6/4/2010 1:01 PM Hans Georg Schaathun said...
> Admittedly not the strongest reason, but yet an important one,
> for switching from Matlab to python/numpy/scipy/matplotlib,
> is that Matlab is very cumbersome to run in batch.
>
> Now I discover that some of the matplotlib.pyplot functions
> (incl. plot and contour) insist on opening an X11 window
> (just like Matlab does).

I found the same to be true when running OpenOffice in batch mode.
Ultimately, the following was key to getting things going:

at the shell:

/usr/bin/vncserver :1


then from within python:

XDISPLAY=':1'

cmd='''cd /usr/ftp/CSV && DISPLAY=%s \
/usr/bin/soffice -norecover -nologo -nodefault \
"macro:///Standard.Module1.csvToXLS(%s)"''' \
% (XDISPLAY,csvfile)

dummy = commands.getoutput(cmd)


Then, if it doesn't run to conclusion, you can vnc to :1 and see where
it's stalled out.

HTH,

Emile


From: exarkun on
On 08:01 pm, h.schaathun(a)surrey.ac.uk wrote:
>Admittedly not the strongest reason, but yet an important one,
>for switching from Matlab to python/numpy/scipy/matplotlib,
>is that Matlab is very cumbersome to run in batch.
>
>Now I discover that some of the matplotlib.pyplot functions
>(incl. plot and contour) insist on opening an X11 window
>(just like Matlab does). I would have preferred just to create
>the plot straight on file. The extra window is a nuisance on my
>laptop, it is deep-felt pain if I try to run it remotely. It fails
>completely if I run it without any display at all.
>
>Oddly, the bar() function does not open a window by default.
>I was very happy with that. It works exactly the way I want.
>(Why isn't pyplot more consistent?)
>
>Is there something I have missed? Is it possible to create
>standard 2D plots and contour plots without a display, writing
>the graphics straight into a PDF file?

It's possible to plot with matplotlib without a display. I'm not
surprised you didn't figure out how, though, it's not all that obvious.

Check out the matplotlib.use function. For example:

import matplotlib
matplotlib.use('agg')
import pylab
pylab.plot([1, 3, 5])
fig = file('foo.png', 'wb')
pylab.savefig(fig, format='png')
fig.close()

This should work fine without a display.

Jean-Paul
From: asdef on
exarkun(a)twistedmatrix.com writes:

> It's possible to plot with matplotlib without a display. I'm not
> surprised you didn't figure out how, though, it's not all that
> obvious.

http://matplotlib.sourceforge.net/faq/howto_faq.html#plotting-howto
,----
| Generate images without having a window popup
`----
From: Hans Georg Schaathun on
On Fri, 04 Jun 2010 22:27:33 -0000, exarkun(a)twistedmatrix.com
<exarkun(a)twistedmatrix.com> wrote:
: It's possible to plot with matplotlib without a display. I'm not
: surprised you didn't figure out how, though, it's not all that obvious.

Thank you very much. That's a good start. Do you know of any good
documentation on how to choose and use backends? What I find
is very thin...

: Check out the matplotlib.use function. For example:
:
: import matplotlib
: matplotlib.use('agg')
: import pylab
: pylab.plot([1, 3, 5])
: fig = file('foo.png', 'wb')
: pylab.savefig(fig, format='png')
: fig.close()

Raster graphics is not good enough, I will need a backend which
does vector graphics and pdf output. AFAICS from the FAQ at
sourceforge, agg only supports raster and png. Cairo supports
vector graphics and PDF, but I cannot find any information about
how/if it deals with X11...

:-- George