user7437554
user7437554

Reputation:

Combine gnuplot with latex: method and output

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.

Upvotes: 3

Views: 1384

Answers (1)

Ethan
Ethan

Reputation: 15118

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.

Upvotes: 8

Related Questions