eng27
eng27

Reputation: 916

Duplex label and tics in gnuplot (epslatex)

I am trying to draw some graphs with reading some values from the file, using epslatex - gnuplot (version 5.0 patchlevel 1), as follows:

# gnuplot.gp
set term epslatex
set output "figure.tex"
set xlabel "x"
set ylabel "y"

set nokey
set size square
set xrange [0:1.0]
set yrange [0:1.0]

do for[idLine = 1 : 4 : 1]{
    a1 = system("cat data.dat | awk 'NR == ".idLine." {print $1}'")
    a2 = system("cat data.dat | awk 'NR == ".idLine." {print $2}'")

    plot x**a1 + a2 with lines lt 1 lc rgb "black"
}

and the data is

# data.dat
1.0 0.0
2.0 0.0
3.0 0.0
4.0 0.0

Though I could managed to draw figure I've wanted, there is still a problem that the labels are getting bolder than a single plot (please see figures below, I hope that the image quality is enough to tell the difference ...). It seems that these phenomenon occur due to the duplex letters of the several times plotting.

I have tried several way to avoid this problem, but non of these didn't work. Is there any smart way to avoid this problem?

Graph with number of plots

Graph with a single plot

Upvotes: 1

Views: 148

Answers (1)

Christoph
Christoph

Reputation: 48390

In your case you can read the whole file into a variable and extract the parameters with word. Then you can iterate over all parameter with plot for ... which generates only a single graph with several plots:

# gnuplot.gp
set term epslatex
set output "figure.tex"
set xlabel "x"
set ylabel "y"

parameters = system("awk '!/^#/' data.dat")
set xrange [0:1]
plot for [i=1:words(parameters):2] x**word(parameters, i) + word(parameters, i+1) with lines notitle

The awk call removes comment lines from your input file. If it doesn't have any comments, you could also use parameters = system("cat data.dat").

Upvotes: 1

Related Questions