1

I'm honestly at a loss. I've honestly tried using gnuplot and LaTeX together but it never seems to give anything desirable. I have the gnuplot code;

reset

set lmargin at screen 0.2;
set rmargin at screen 0.977;
set tmargin at screen 0.96;
set bmargin at screen 0.13;

# Define colour range to be consistent amongst plots
set cbrange [lowcol:highcol];


set terminal latex
set out 'psi.tex'
set termoption dash

#set title istitle;
set xlabel '$x/a$';
set ylabel '$y/a$' offset 1.7;
set contour;
set view map;
unset surface;
set cntrparam levels 8;
set isosamples 50;
unset key
unset colorbox
splot 'loop_bottom.txt' w l notitle,'loop_top.txt' w l notitle

and the minimal package

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{psi.tex}
\end{document}

and I get something that looks like

enter image description here

Which is kind of okay. But the lines are very grainy, I also need the x-axis half the size and "set size 0.5,1" doesn't seem to be working. Unfortunately I can't put the text files that contain the data points on here, but would there be a better (and easily understandable, the deadline for this project is very soon) to be able to plot a monochromatic contour plot of data points in LaTeX, like the one in the picture?

  • If you care about the quality of your plots, then you should consider using pgfplots instead (pgfplots.sourceforge.net). I use it for all my plots, and it is very easy to use. I find it easier than MATLAB or GNUPlot. You can also control the desirable color in pgfplots. – puser May 11 '14 at 1:45
  • You should have a look at the answers to PGFplots and GNUplot with addplot3 as they seem very appropriate to your question. Let us know if it resolves the issue :) – cmhughes May 11 '14 at 2:53
2

The latex terminal option seems to write a lot of individual plot points into the psi.tex file, disregarding the (mathematical) connection between them, or shorter, the result is not a vector graphic format. This leads to grainy pictures, especially if scaled. Increasing the isosamples will provide better graphic files if applied in conjunction with better increased samples, but this not an option if an data file is plotted instead of a function.

My 'solution' uses a function, since the files in the gnuplot script are not available to me.

I would suggest using the postscript or pdf terminals.

reset

set lmargin at screen 0.2;
set rmargin at screen 0.977;
set tmargin at screen 0.96;
set bmargin at screen 0.13;

# Define colour range to be consistent amongst plots
# set cbrange [lowcol:highcol];



#set title istitle;
set xlabel '$x/a$';
set ylabel '$y/a$' offset 1.7;
set contour;
set view map;
unset surface;
set cntrparam levels 8;
set isosamples 200;
unset key
unset colorbox
splot sin(x*y)   
# Commented out since data file `loop_*.txt' not available
#splot 'loop_bottom.txt' w l notitle,'loop_top.txt' w l notitle

set terminal push

set terminal latex 
set out 'psi.tex'
set termoption dash
replot
set out

set terminal postscript enhanced colour
set output 'psi.eps'
replot
set out

set terminal pdf colour
set output 'psi.pdf'
replot
set out

set terminal pop

Here comes the LaTeX code

\documentclass{article}
\usepackage{graphicx}
% Perhaps necessary, depending on plot symbols
\usepackage{latexsym}
\begin{document}

\input{psi}

\includegraphics[scale=0.5,angle=-90]{psi.eps}

\includegraphics{psi.pdf}


\end{document}

Gnuplot latex terminal output

enter image description here

Gnuplot postscript terminal output

enter image description here

  • 1
    The problem with the latex terminal is that it uses the picture environment to draw the plot. The epslatex terminal creates a postscript image plus LaTeX code to create labels etc. – Ian Thompson May 11 '14 at 8:13
  • @IanThompson: I thought about epslatex but had no time to figure it out. – user31729 May 11 '14 at 8:19
  • I second Ian, epslatex is much better than latex and you can use the same font of the document – giordano Jan 9 '16 at 20:24
  • @giordano: Perhaps, but I don't use neither latex nor epslatex terminals for 15 years now. If you think you have a better solution feel free to provide it here. – user31729 Jan 9 '16 at 21:01
0

The epslatex terminal is much better than the latex one, and you can still keep consistency with fonts of the main document, that you would loose when using other terminals like pdf or postscript. I honestly can't think of any single reason to use latex instead of epslatex.

For example, with this code

reset
set terminal epslatex
set output 'foo.tex'

set xlabel '$x/a$'
set ylabel '$y/a$' offset -1,0
set contour
set view map
unset surface
set cntrparam levels 31
set isosamples 200
unset key
unset colorbox

splot x**2-y**2
set output

you can get the following image

enter image description here

If you want to set the ratio between the axes, use the size ratio option. For example, with

set size ratio 2

the y axis is twice the x axis. If you want the whole "x" size of the plot to be halved, set the size of the whole figure in terminal options remembering that the default size is 5×3.5 inches². For example, the following code sets the size of the picture to 2.5×3.5 inches²

set terminal epslatex size 2.5,3.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.