1

When I try to write a shell script such as

gnuplot
cd '/home/cagirici/test'
plot "case1.test" with linespoints

and run it in sudo, the script stops after running gnuplot.

In each .test file, I have 12 columns. I won't plot them all at once but choose what to plot. For instance, if I choose to plot the success percentage, it should plot 1:2 and 1:8. But if I choose error percentage, it should plot 1:4 and 1:10 (it is basically i:(i+6).)

I need to write a scripts that takes two inputs: i) file name ii) what to plot.

Notice that I also want to choose the line type, point type and output shell. (if there is a configuration to set specific line and point types as default values, please tell me this as well)

Can I write this script in Ubuntu? Or should I use a different method.

My script would look something like

case "$2" in
("success percentage") plot "$1" using 1:2, plot "$1" using 1:8
("error percentage") plot "$1" using 1:4, plot "$1" using 1:10

2 Answers 2

2

You can make this work by creating a Gnuplot script with variables and then passing values to these variables at run time from command line or your bash script.

Lets call the Gnuplot script Myscript.gp:

set terminal pngcairo
set output 'graph.png'

plot file u x:y w linespoints

Here file and x:y can be varried when you invoke Gnuplot from your bash script. A possible call to Myscript.gp is as follows:

gnuplot -e "x=1;y=2;file = \"mydata.dat\"" Myscript.gp

In the snippet of your bash script that you provide this may look like:

case "$2" in
("success percentage") gnuplot -e "x=1; y=2; file = \"$1\"" Myscript.gp

Below I'm also providing a dummy mydata.dat file which you can use to try things.

1.54    23.66   43.66
1.75    26.25   46.25
1.92    30.20   40.20
2.08    34.46   44.46
2.44    42.08   42.08
2.78    46.81   46.81
3.03    51.10   41.10
3.70    52.99   42.99
4.17    56.15   46.15
4.76    59.34   49.34

If you are calculating the column numbers (x and y) in your bash script then you can also use variables inside the plot command.

gnuplot -e "x=$x;y=$y;file = \"mydata.dat\"" Myscript.gp

Below I show the output once using:

gnuplot -e "x=1;y=2;file = \"mydata.dat\"" Myscript.gp

and once

gnuplot -e "x=1;y=3;file = \"mydata.dat\"" Myscript.gp

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I had faced similar problem 2 years back, then my senior team members decided to write a tool for plotting graphs using a simple csv and plotting specifications and tool will plot graphs for you,

Initially it was designed for sar data on linux so named RSAR but in general it is a csv plotter.) if required you can contact me [email protected]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.