MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Piping commands to gnuplot through the shell

  • To: mathgroup at
  • Subject: [mg67460] Piping commands to gnuplot through the shell
  • From: MDP <news.x.zokota at>
  • Date: Mon, 26 Jun 2006 00:13:06 -0400 (EDT)
  • Organization: University of California, Berkeley
  • Sender: owner-wri-mathgroup at


I am currently writing some Mathematica code that will plot data with
gnuplot instead of the internal plotting functions.  I have successfully
written a function that opens the gnuplot pipes executable as a stream where
I can send it a list of arbitrary commands and end up with my desired
output.  This is great for making presentation quality plots but the problem
is that after the function ends and gnuplot is exited there is still a
process running as indicated by Windows Task Manager.  The window that gets
opened during command piping gets closed but the executable does not and I
can't figure out what I'm doing wrong.  If I run the function multiple times
I end up with multiple processes running so each time I use
pstream=OpenWrite["!pgnuplot"] Mathematica starts a new process that
Close[pstream] doesn't seem to stop.  Does anyone have an idea how to close
it or any ideas on how I could run gnuplot through Mathematica a better way?
  Thanks for any insight... here is my code:

gnuplot2D[data_, opts___] := Module[
         gnuplotDirectory = "c:/program
       files/gnuplot/bin/", tempDirectory = "c:/program files/gnuplot/"=,
         aspectRatio = gnuplotAspectRatio /. {opts} /. \
         commands, j, thePlot

       commands = {"reset",

           "set datafile separator \",\"",
           "set size ratio " <> ToString[N[aspectRatio, 3 ]],
           "set terminal postscript eps enhanced color \"ArialMT\" 24",
           "set output \"" <> tempDirectory <> "temp.eps" <> "\"",
           "plot  \"" <> tempDirectory <> "temp.csv" <> "\" matrix notitle",

       Export["temp.csv", data];
       pstream = OpenWrite["!pgnuplot"];
       For[j = 1, j =E2=89=A4 Length[commands], j++, OutputForm[
           commands[[j]]] >> !pgnuplot;];
       Run["del temp.csv"];

Options[gnuplotScatter] = {gnuplotAspectRatio -> 1/GoldenRatio};

  • Prev by Date: Re: Integrate the Multivariate normal distribution
  • Next by Date: Re: Points sampled by NIntegrate
  • Previous by thread: Re: Integrate the Multivariate normal distribution
  • Next by thread: 3D Plot (or ListPlot?) Question