3

I'm running the following script:

#!/bin/bash
gnuplot -e "set t latex ; set size 0.5,1; set output 'grafico.tex';
 set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2); set xrange [-pi/2:pi/2]; 
 set yrange [-2:2]; set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x); pause -1 'hit return to continue'"
pdflatex latex
atril latex.pdf

Output 1

output

As a beginner both with programming and gnuplot, I want to be sure that's the correct way to do it. My doubt come from the output, it doesn't looks very good (the resolution, mainly). Is there any simple improvement i'm missing? Any change to improve the plotting technique and enhance the result will be welcome.


Output 2

Changing latex to cairolatex pdf as suggests @Ethan Merritt returns:

out2

which is much better.

1 Answer 1

8

gnuplot's original latex terminal, the one you get by saying "set term latex", is horrible by modern standards. Use one of the more recent ones. My favorite is the tikz terminal:

gnuplot>

set term tikz standalone size 5cm, 7cm
set output 'grafico.tex'
set xtics ('$\frac{-\pi}{2}$' -pi/2, 0, '$\frac{\pi}{2}$' pi/2)
set xrange [-pi/2:pi/2]; set yrange [-2:2];
set ylabel '$ f(x)$'; set xlabel '$\theta$';
plot sin(x)
unset output
system("pdflatex grafico")

Notes:

  • You should probably set the size as part of the set term command. If you use set size your output will contain large blank areas

  • Your local copy of gnuplot might not support the tikz terminal. In that case you could use set term cairolatex pdf instead, with everything else the same.

  • gnuplot has other (too many!) latex-based terminals also, but I suggest starting with tikz or cairolatex.

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

2 Comments

unset output "close" the file? And is there any reason to avoid script execution with bash?
Yes, unset output closes the file. Too hard to type bash scripts in the window :-) Also I prefer to avoid the extra layer of interpretation and variable substitution.

Your Answer

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