[IPOL discuss] matplotlib? + decisions + postscript experiment

Nicolas Limare nicolas.limare at cmla.ens-cachan.fr
Mon Oct 31 04:51:37 CET 2011


> A C program can open a pipe to communicate with the plotting library
> (gnuplot has few dependencies, as Nicolas explained in a previous
> message), configure it, recover the plot from the pipe and save a
> raster/vector output file.

You probably don't really mean to open the pipe from the program,
because the "int pipe (int fildes[2]);" function is a UNIX thing,
declared in unistd.h[1], and I think you can't open a pipe from a
program to another program, only a pipe to a subprocess (via "pid_t
fork(void);", another UNIX thing[2]).

[1]http://pubs.opengroup.org/onlinepubs/009604599/functions/pipe.html
[2]http://pubs.opengroup.org/onlinepubs/7908799/xsh/fork.html

So, if you meant an external pipe (like "myprogram ... | gnuplot"),
probably created by the shell, then this pipe is not necessary and you
can as well use a file instead, to avoid the need for a shell and UNIX
pipe:
  myprogram ... -o data.plt
  gnuplot data.plt

> This way we wouldn't be forcing authors to write their own plotting system
> and we solve the package-dependency problem in the server at the same
> time.

If the direct text (PostScript/SVG) drawing strategy proposed by
Rafael is not chosen, then in my opinion depending on gnuplot is
currently better than depending on matplotlib, because of the
dependencies and because of the stability. gnuplot is an old software,
working on many different systems including UNIX and Windows, and
version 4.0 was released in 2004.

# How to decide?

I don't want to be too involved in the discussion, it's a good
opportunity to have some IPOL decisions not taken by me. So once every
argument has been exposed and discussed on this list, maybe you can
take a few minutes for a meeting between people involved in IPOL in
Cachan, and decide how you want every algo/demo to handle graph
output.

# PostScript experiment

I was also curious about the feasability of graph drawing with
PostScript. The text hereafter is my first attempt at writing an
eps file; it's a PostScript program, in fact, because PostScript is a
programming language. It took me ~2h from the documentation found
online, and I think it is a good example of what can be done. The EPS
file (exacty the same content as below) and a PNG version are attached
to this mail. As you can see, we can draw a graph with 36 lines of
text, including the 24 lines to draw and label the axis (% marks
comments, except in the first 2 lines). My interpretation of this
little experiment is that drawing simple graphs with PostScript is
easy. We can probably do the same thing with SVG, I did not try.

8<----------8<----------8<----------8<----------8<----------8<----------
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 250 250
% first, a function to convert from millimeters to PostScript points
% 1 mm = 360 / 127 pt
/mm { 360 mul 127 div } def
% then, a function to express positions in the xy coordinate
% (0,0) is at (20mm,20mm), and 1 unit in the xy scales takes 10mm
/xy { mm 10 mul 20 mm add } def
%
% DRAW THE COORDINATE AXIS
%
% set the linewidth to .1mm and color to black
.1 mm setlinewidth
0 setgray
% chose Arial 3mm for text
/Arial 3 mm selectfont
% draw and label the x axis line
-1 xy 0 xy newpath moveto
 5 xy 0 xy lineto stroke
 5 xy -.5 xy moveto (x) show
% draw and label the y axis line
0 xy -1 xy newpath moveto
0 xy  5 xy lineto stroke
-.5 xy 5 xy moveto (y) show
% a function for values on the x axis
/xval {
    dup dup                 % x position used 3 times
    -.1 xy newpath moveto   % start mark
    .1 xy lineto stroke     % end and draw mark
    -.5 xy moveto show      % add text
} def
% x axis values 1, 2, 3, 4
(1) 1 xy xval
(2) 2 xy xval
(3) 3 xy xval
(4) 4 xy xval
% a function for values on the y axis
/yval {
    dup dup                    % y position used 3 times
    -.1 xy exch newpath moveto % start mark
    .1 xy exch lineto stroke   % end and draw mark
    -.5 xy exch moveto show    % add text
} def
% x axis values 1, 2, 3, 4
(0) 1 xy yval
(2) 2 xy yval
(3) 3 xy yval
(4) 4 xy yval
% set the linewidth to .1mm and color to red
.2 mm setlinewidth
1 0 0 setrgbcolor
%
% DRAW THE DATA
%
% draw the line segments
1.0 xy 1.0 xy newpath moveto
2.0 xy 3.5 xy lineto
3.0 xy 2.3 xy lineto
4.0 xy 2.2 xy lineto stroke
% draw the points as circles
1.0 xy 1.0 xy 0.5 mm 0 360 arc closepath fill
2.0 xy 3.5 xy 0.5 mm 0 360 arc closepath fill
3.0 xy 2.3 xy 0.5 mm 0 360 arc closepath fill
4.0 xy 2.2 xy 0.5 mm 0 360 arc closepath fill
% display everything
showpage

-- 
Nicolas LIMARE - CMLA - ENS Cachan    http://www.cmla.ens-cachan.fr/~limare/
IPOL - image processing on line                          http://www.ipol.im/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot.eps
Type: application/postscript
Size: 1752 bytes
Desc: not available
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20111031/bebda3a1/attachment.eps>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot.png
Type: image/png
Size: 1477 bytes
Desc: not available
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20111031/bebda3a1/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://tools.ipol.im/mailman/archive/discuss/attachments/20111031/bebda3a1/attachment.pgp>


More information about the discuss mailing list