How to start working with GNU PLOT??

Dear Experts,

I wanted to plot a graph with respect to values from a file.
I'm doing it with Excel 2007, but I want to create the chart in script itself.
I searched in internet for GNUPLOt. But I couldn't understand anything.
Here is my situation. I have a file having values separated by "|".

report:~/Naga # head SCP_CAPS_24012012.txt 
00:00:00|20.62|7.85|12.05|12.40|16.73|16.38|13.80|5.23|11.87|7.48|2.35|10.42
00:01:00|22.83|9.88|14.75|13.70|15.80|18.63|14.00|5.70|13.83|9.47|2.65|10.53
00:02:00|21.87|8.97|14.00|12.78|14.83|17.05|14.52|6.82|13.53|9.32|2.73|10.32
00:03:00|21.42|7.50|12.55|12.78|15.32|16.60|14.32|5.97|12.28|8.35|2.05|10.70
00:04:00|19.38|7.52|11.67|11.58|14.45|15.65|12.98|5.45|11.77|8.18|2.20|9.90
00:05:00|20.28|7.43|10.40|11.33|13.95|15.33|12.05|5.73|11.77|8.40|2.10|9.50
00:06:00|19.40|7.65|10.45|11.38|14.40|15.95|13.05|5.97|11.83|7.53|2.28|10.43
00:07:00|19.20|6.88|10.92|10.80|13.65|15.08|12.88|5.90|10.13|7.23|2.58|10.22
00:08:00|18.95|6.97|10.02|10.40|14.12|14.20|12.72|5.20|10.30|7.48|1.85|9.27
00:09:00|19.60|6.95|9.22|11.25|13.17|14.25|13.13|5.50|10.47|7.10|2.20|9.85

First column is time, Second is node1,node2 and so on. I need to plot a line graph with column1 and 2, column1 and 3 .......... resulting in 13 graphical outputs which I want to store in a file.

I tried to generate a graph but I am not successful.

gnuplot> load "SCP_CAPS_24012012.txt"

gnuplot> 00:00:00|20.62|7.85|12.05|12.40|16.73|16.38|13.80|5.23|11.87|7.48|2.35|10.42
         ^
         "SCP_CAPS_24012012.txt", line 1: invalid command

Pls help with your ideas and suggestions to do this.

Very good samples and tutorials are here:
gnuplot tips (not so Frequently Asked Questions)
Basic plotting is really simple:

gnuplot> set datafile separator "|"
gnuplot> plot 'file.dat' u 1:2 t 'Title for col2, 'file.dat' u 1:3 t 'Title for col3'

and so on...

Thanks sulti........ But still if I give plot sin(x) also, I am nt getting any output.

That's weird... Which system and what version of gnuplot are You using? Are You working on Your local computer or somewhere remote? How did You install gnuplot - repositories or compiling on Your own? :slight_smile:

I am getting below output after setting the terminal to postscript.

gnuplot> plot sin(x)
%%Page: 2 2
gnudict begin
gsave
50 50 translate
0.100 0.100 scale
90 rotate
0 -5040 translate
0 setgray
newpath
(Helvetica) findfont 140 scalefont setfont
1.000 UL
LTb
714 420 M
63 0 V
6185 0 R
-63 0 V
630 420 M
gsave 0 setgray
(-2) Rshow
grestore
1.000 UL
LTb
714 977 M
63 0 V
6185 0 R
-63 0 V
630 977 M
gsave 0 setgray
(-1.5) Rshow
grestore
1.000 UL
LTb
714 1533 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
(-1) Rshow
grestore
1.000 UL
LTb
714 2090 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
(-0.5) Rshow
grestore
1.000 UL
LTb
714 2646 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
( 0) Rshow
grestore
1.000 UL
LTb
714 3203 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
( 0.5) Rshow
grestore
1.000 UL
LTb
714 3759 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
( 1) Rshow
grestore
1.000 UL
LTb
714 4316 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
( 1.5) Rshow
grestore
1.000 UL
LTb
714 4872 M
63 0 V
6185 0 R
-63 0 V
-6269 0 R
gsave 0 setgray
( 2) Rshow
grestore
1.000 UL
LTb
714 420 M
0 63 V
0 4389 R
0 -63 V
714 280 M
gsave 0 setgray
( 0) Cshow
grestore
1.000 UL
LTb
1964 420 M
0 63 V
0 4389 R
0 -63 V
0 -4529 R
gsave 0 setgray
( 1) Cshow
grestore
1.000 UL
LTb
3213 420 M
0 63 V
0 4389 R
0 -63 V
0 -4529 R
gsave 0 setgray
( 2) Cshow
grestore
1.000 UL
LTb
4463 420 M
0 63 V
0 4389 R
0 -63 V
0 -4529 R
gsave 0 setgray
( 3) Cshow
grestore
1.000 UL
LTb
5712 420 M
0 63 V
0 4389 R
0 -63 V
0 -4529 R
gsave 0 setgray
( 4) Cshow
grestore
1.000 UL
LTb
6962 420 M
0 63 V
0 4389 R
0 -63 V
0 -4529 R
gsave 0 setgray
( 5) Cshow
grestore
1.000 UL
LTb
1.000 UL
LTb
714 420 M
6248 0 V
0 4452 V
-6248 0 V
714 420 L
LTb
140 2646 M
gsave 0 setgray
currentpoint gsave translate 90 rotate 0 0 M
(Y-AXIS) Cshow
grestore
grestore
LTb
3838 70 M
gsave 0 setgray
(X-AXIS) Cshow
grestore
1.000 UP
1.000 UL
LT0
LTb
6311 4739 M
gsave 0 setgray
(sin\(x\)) Rshow
grestore
LT0
6395 4739 M
399 0 V
714 2646 M
63 56 V
63 56 V
63 56 V
63 55 V
64 55 V
63 54 V
63 53 V
63 53 V
63 51 V
63 50 V
63 48 V
63 47 V
63 45 V
64 44 V
63 42 V
63 40 V
63 37 V
63 36 V
63 34 V
63 31 V
63 28 V
63 26 V
64 24 V
63 21 V
63 19 V
63 15 V
63 13 V
63 10 V
63 8 V
63 4 V
63 2 V
64 -1 V
63 -4 V
63 -7 V
63 -10 V
63 -12 V
63 -15 V
63 -18 V
63 -20 V
63 -24 V
64 -25 V
63 -28 V
63 -31 V
63 -33 V
63 -35 V
63 -37 V
63 -40 V
63 -41 V
63 -44 V
64 -45 V
63 -46 V
63 -48 V
63 -50 V
63 -51 V
63 -52 V
63 -53 V
63 -54 V
63 -54 V
64 -56 V
63 -55 V
63 -56 V
63 -57 V
63 -56 V
63 -56 V
63 -56 V
63 -55 V
63 -55 V
64 -54 V
63 -54 V
63 -52 V
63 -51 V
63 -50 V
63 -49 V
63 -48 V
63 -45 V
63 -44 V
64 -42 V
63 -41 V
63 -38 V
63 -36 V
63 -34 V
63 -31 V
63 -30 V
63 -26 V
63 -25 V
64 -21 V
63 -19 V
63 -16 V
63 -14 V
63 -11 V
63 -7 V
63 -6 V
63 -2 V
63 1 V
64 3 V
63 6 V
63 9 V
63 12 V
63 15 V
1.000 UL
LTb
714 420 M
6248 0 V
0 4452 V
-6248 0 V
714 420 L
1.000 UP
stroke
grestore
end
showpage
gnuplot> 

Now I have set output to a file. But its not in Graphical format.

---------- Post updated at 04:48 PM ---------- Previous update was at 04:46 PM ----------

I am using gnuplot version 4.0 ........ on a remote system.

Ok, so You have to set output terminal different. Try this:

set terminal png         # gnuplot recommends setting terminal before output
set output "output.png"  # The output filename; to be set after setting
		 	 # terminal
plot sin(x)

First, you create a Gnuplot template (template.gp)

set datafile separator "|"
set xdata time
set timefmt '%H:%M:%S'
set terminal png
set output 'column-@COLUMN@.png'
set yrange [0:]
set title 'column @COLUMN@'
set grid
plot 'SCP_CAPS_24012012.txt' using 1:@COLUMN@ title 'column @COLUMN@' with linespoints 

Now you can dynamically substitute @COLUMN@ with the actual column number and create all the graphs in a loop

for i in 2 3 4 5 6 7 8
do
    sed "s/@COLUMN@/$i/g" template.gp | gnuplot - > /dev/null 2>&1
done

BTW, you can also plot all the columns in one single PNG file

1 Like

Thanks a lot Chihung........... Its working great..........