Plotting in batch with no display

Tim Harig usernet at ilthio.net
Mon Jun 7 16:28:33 EDT 2010


On 2010-06-07, Hans Georg Schaathun <H.Schaathun at surrey.ac.uk> wrote:
> On Sat, 5 Jun 2010 16:10:01 +0000 (UTC), Tim Harig
>  <usernet at ilthio.net> wrote:
>:  On 2010-06-05, Hans Georg Schaathun <H.Schaathun at surrey.ac.uk> wrote:
>: > 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...
>: 
>:  1. I am not familiar with matlab;
>
> Good that my question did not concern matlab then :-)

Sorry for the disclaimer. Matlab seemed to be referenced quite a bit and
since I am not familiar with it, I am likely to misunderstand something
that might otherwise be obvious.

>:                                    but, I have written python programs that
>:  	generate plots using GNUplot (which can create PDFs).  There are
>:  	python modules available for working with GNUplot or you can open
>:  	it yourself under a subprocess and send it commands through a pipe.
>:  	GNUplot allows you to save files directly and does not therefore
>:  	require X.
>
> That certainly is an option.  I actually do have an example using
> gnuplot, taken from the libsvm tools which I wanted to replace with 
> a native python solution :-)  After some testing, I have concluded
> though, that that's not necessary.  OTOH, gnuplot is not quite as
> easy to learn as the pyplot API.

GNUplot is very easy to learn.  I started using it after reading a three
page tutorial.  After you get the idea of how it works, everything else is
just details that you can learn from the online help pages from within
GNUplot itself.

I have never actually used any API to access GNUPlot from python as I
already knew the commands anyway so I have always just given my own data
objects the capability to send the necessary commands through the pipe.
However, just looking at the demo code file for the API at:

http://gnuplot-py.sourceforge.net/

I looks like I could basically use it just based on my GNUplot knowledge.
Its really just a *very* transparent class encapsulation of the GNUplot
commands. (And it creates the same pipe that I use for my code on the
backside)

>:  3. Depending on your requirements, you could generate a plot using
>:  	postscript.  Postscript is  easy to convert directly to PDF as
>:  	the two are closely related. As postscript is a powerful
>:  	language itself you can actually write the graphing routines in
>:  	postscript and use python to simply embed the data into the
>:  	postscript.
>
> Sure, but the problem is to find the right matplotlib engine to do 
> that.  We live in 2010 and Python is a new and evolving language.

I just through it out there as a possible option.  This is not the kind of
thing that is probably useful for most projects; but, it can be extremely
useful for some situations.

Having a viewing environment based on a Turing complete language means
that you can implement a flexible MVC view componet that the user can
use to manipulate the view of the data simply for the price of having
a Postscript viewer.  This leaves your application free to focus solely on
the business logic.  For comparison, think about an AJAX based web page
where the client merely receives structured data from the server (XML,
JSON, etc) and javascript on the client actually allows the user to choose
how the data is viewed.

Sending data embedded in a postscript file also means that the data is
sent, and can be independantly extracted, along with the graph image itself.

> It would be strange if the PS renderer is more advanced than the
> PDF renderer, but if it is, I'll use it.

I frankly don't know much about PDF other than it is a technology closely
related to Postscript.  I have heard it phrased that PDFs are essentially
based on Postscript technology where the loops have been "unrolled."  I
personally think of PDFs as a form of compiled Postscript where the program
is executed and the results are simply saved and there is no way to
re-execute the program using different data.

As far as the language itself, I find Postscript to be rather intriguing.
It uses a very different philosophy from Python; but, it has some really
neat features that I haven't really seen in other langauges.

> Ideally, I'd like the option to switch between X11 and file output
> runtime, which the engine switch (matplotlib.use()) does not support.
> Question is, is there an engine to do that?

GNUplot chooses its outputs by setting the "terminal" variable.  Terminal
can be set to a text terminal, a graphical terminal, or a number of
different file formats.



More information about the Python-list mailing list