Joaquin Peralta

My Personal weblog.

Fast plot from bash.

Usually i need make tentative graphics of a data set, and this require use gnuplot, with command and others things, for this reason i make a little script for plot directly from the bash with arguments (file and options) using gnuplot (you need gnuplot installed in your system).

For example for plot a simple file with data (as here). a fast plot is made using :

xplot example.dat

For a more complex file as here, you can plot using :

xplot freefall.dat u 1:2 w lp

The script for plot from the bash its here :

#!/bin/sh
TMP="/tmp/gnuplot.tmp"
############################################################################
if [ $# != 0 ];
then
echo "set title \"Xplot Fast Plot with gnuplot\" ." > $TMP
echo "set xlabel \"x axes\"" >> $TMP
echo "set ylabel \"y axez\"" >> $TMP
echo -n "plot \"$1\" " >> $TMP
for i in $@
do
if [ $i != $1 ];then
echo -n "$i " >> $TMP
fi
done
echo "">>$TMP
gnuplot -persist $TMP
rm $TMP
else
echo "Please use xplot <file.dat> <options> to plot"
exit
fi

Now you can put this file in /usr/local/bin/ (with xplot or another name) and give execution permissions with :

chmod 755 /usr/local/bin xplot

Now, any user can run the xplot script.

JP.

May 4, 2007 - Posted by jperalta | GNU/Linux | | 4 Comments

4 Comments »

  1. It’s quite pretty… Simple, accurate and powerful. Thanks dude!

    Comment by AlCapone | May 4, 2007 | Reply

  2. i am using the code in cygwin and i am not able to get any graph. Is the graph stored somewhere? sorry i am newbie to bash

    Comment by krishna | October 16, 2008 | Reply

  3. Hi, sorry for the later answer (a lot of work). The problem is that with cygwin its not easy run gnuplot for see graphs, i don’t know how is the real procedure for see gnuplot graphs with cygwin.

    You can run gnuplot and see for examples : “plot sin(x)” ?

    Waiting your answer.
    JP

    Comment by jperalta | November 3, 2008 | Reply

  4. Hi, sorry for the later answer (a lot of work). The problem is that with cygwin its not easy run gnuplot for see graphs, i don’t know how is the real procedure for see gnuplot graphs with cygwin.

    You can run gnuplot and see for examples : “plot sin(x)” ?

    Waiting your answer.
    JP

    Comment by jperalta | November 3, 2008 | Reply


Leave a comment