How to start working with GNU PLOT??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to start working with GNU PLOT??
# 1  
Old 01-25-2012
Question 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 "|".
Code:
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.
Code:
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.
# 2  
Old 01-25-2012
Very good samples and tutorials are here:
gnuplot tips (not so Frequently Asked Questions)
Basic plotting is really simple:
Code:
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...
# 3  
Old 01-25-2012
Thanks sulti........ But still if I give plot sin(x) also, I am nt getting any output.
# 4  
Old 01-25-2012
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? Smilie
# 5  
Old 01-25-2012
I am getting below output after setting the terminal to postscript.
Code:
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.
# 6  
Old 01-25-2012
Ok, so You have to set output terminal different. Try this:
Code:
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)

# 7  
Old 01-25-2012
First, you create a Gnuplot template (template.gp)
Code:
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
Code:
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

Last edited by chihung; 01-25-2012 at 08:38 PM..
This User Gave Thanks to chihung For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. What is on Your Mind?

Has Python Lost The Plot?

Not sure if this should be in the Programming forum so placed here for safety... I used to really love Python, but as it has evolved from V1.4.0, (for the classic AMIGA in my case), to its present V3.4.? incarnation has it become less user friendly for newbie and amateur coders? I have... (6 Replies)
Discussion started by: wisecracker
6 Replies

2. Shell Programming and Scripting

Ls help: ls not working with start character search (^)

Experts, How to list a file using ^ character, for all files started with character a. (os= hp-ux ) # ls -l -rw------- 1 useradm users 0 Mar 26 14:30 abc -rw------- 1 useradm users 0 Mar 26 14:30 def -rw------- 1 useradm users 0 Mar 26... (7 Replies)
Discussion started by: rveri
7 Replies

3. Slackware

pppoe-start not working

Hello. I'm new here and i'm new to slack (concept) as well. I made a connection for pppoe with pppoe-setup, bringed up eth0 with ifconfig but when i try pppoe-connect i get "Cannot determine ethernet address for proxy ARP" and with pppoe-start i get "child pppd process terminated". How can i make... (0 Replies)
Discussion started by: editheraven
0 Replies

4. Solaris

Solaris 10, start inetd in a zone not working

Hello all, I`ve the following problem - I cannot start inetd in any way possible: bash-3.00# svcs inetd STATE STIME FMRI offline Jul_30 svc:/network/inetd:default bash-3.00# bash-3.00# svcadm enable -r inetd bash-3.00# svcs inetd STATE STIME FMRI... (6 Replies)
Discussion started by: click
6 Replies

5. Shell Programming and Scripting

gnu sed regex grouping not working?

Hello, from the gnu sed manual, I should be able to do this: `\(REGEXP\)' Groups the inner REGEXP as a whole, this is used to: * Apply postfix operators, like `\(abcd\)*': this will search for zero or more whole sequences of `abcd', while `abcd*' ... (3 Replies)
Discussion started by: Allasso
3 Replies

6. UNIX for Dummies Questions & Answers

Working out end time from start + elapsed

Hi, I'm writing a script and have become stuck trying to define a variable (COMP) by adding an elapsed time (ELAPSE e.g 00:55) to a start time (START e.g 23:50). Can anybody give me a solution as to how I can get a completion time in hh:mm from the variables above? thanks Richard (4 Replies)
Discussion started by: rik1551
4 Replies
Login or Register to Ask a Question