1

file (1. arg) will create (scatter plot) for n. column (x-axis, 2. arg) and m. column (y-axis, 3. arg)

function is called myfun sourcefile 1 3 for scatter plot of 1. and 3. column from file sourcefile.

#!/bin/bash/gnuplot

myfun(){
 plot "$1" using $2:$3
}
myfun sourcefile 1 3

In gnuplot> plot sourcefile using 1:3 works perfectly. I want it to run inside the function. How?

karel
  • 122,292
  • 133
  • 301
  • 332
Martin Yeboah
  • 241
  • 4
  • 11

2 Answers2

2

I really do not know what kind of script is that one. Where did you find it? .../bash/gnuplot seems that someone is getting really confused.

But if you have the file with the data, call it sourcefile, with the structure

whatever  x-data y-data
whatever  x-data y-data
whatever  x-data y-data

you can have a scatter plot of column 3 versus column 2 entering gnuplot, and at the prompt using:

plot "sourcefile" using 2:3

(Although your script seems to be doing plot "sourcefile" using 1:3, in contrast with your description, and without quotes which is a syntax error in gnuplot unless sourcefile is a variable containing the name of the file).

I recommend you to read http://people.duke.edu/~hpgavin/gnuplot.html

Rmano
  • 32,167
2

I'd suggest using a shell here document in this case

#!/bin/bash

function myfun {
cat << EOF | gnuplot -p
plot "$1" using $2:$3
EOF
}

Then

myfun sourcefile 1 3
steeldriver
  • 142,475