1

I have two different text files which have a data column and a value column each. Ĩ wanted to plot both using a 'plot for' loop but I wanted to changed the name of the output to match the file I'm plotting. Right now my code looks like this:

set terminal postscript eps color
set out "test.eps"
set size 0.6
set multiplot
set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"
filenames = 'ArcheryData.txt CanyoningData.txt'
plot for [file in filenames] file u 1:2 w l title file

What I get now is the test.eps file which has the two data files plotted in the same graph.

1 Answer 1

1

In that case, you might use the do loop as:

set terminal postscript eps color
set size 0.6

set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"

do for [ name in "ArcheryData CanyoningData" ]{
    set output name.".eps"
    plot name.".txt" u 1:2 w l title name
}

Alternatively, the variable name could be specified when invoking Gnuplot, thus with a script as:

set terminal postscript eps color
set size 0.6

set xdata time
set timefmt "%Y-%m"
set format x "%b\n%y"
set xtics "2004-01", 12*2629746, "2016-12"

set output name.".eps"
plot name.".txt" u 1:2 w l title name

one might then use it as gnuplot -e "name='ArcheryData';" fig.gpl

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

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.