Wednesday, January 25, 2012

High quality LaTeX figures using gnuplot - take 2

This is another way to make high quality figures for use in journal publications.  We will be using gnuplot and LaTaX to generate the figure.  Gnuplot will create an *.eps file that contains the image (lines and axes) and LaTeX will produce the text on the plot using the same font as the rest of your document, creating figures that look great.

Step 1: Create the image files using gnuplot

>> gnuplot
gnuplot>> set term epslatex
gnuplot>> set output "test_figure.tex"
gnuplot>> set xlabel '$\lambda_\theta$'
gnuplot>> set ylabel '$\omega - \mathrm{pi}$'
gnuplot>> set title 'This is a test'
gnuplot>> p sin(x) t 'sin(x)', cos(x) t 'cos(x)'
gnuplot>> exit
>>


Which should have made two files: test_figure.tex and test_figure.eps

Step 2: Compile figure in LaTeX document

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\input{test_figure.tex}
\end{figure}
\end{document}

This code can be compiled using pdflatex and will produce the following figure:

LaTeX circuit diagrams

Making circuit diagrams in LaTeX documents is easy with the circuitikz package.  The following image can be created using the code below.




\documentclass{article}
\usepackage[free-standing-units]{siunitx}
\usepackage[american]{circuitikz}
\usepackage{tikz}

\begin{document}

\begin{figure}[h!]
\centering
\begin{circuitikz} \draw
(0,0) to[V, l=$9V$](0,4)
(0,4) -- (4,4)
(4,4) to[R, l=$R>470\ohm$] (4,2)
(4,2) to[led, l=LED](4,0)
(4,0) -- (0,0)
;
\end{circuitikz}
\caption{Base circuit}\label{fig:circuit1}
\end{figure}

\end{document}


The manual with complete list of symbols can be downloaded from
 http://tug.org/texlive/devsrc/Master/texmf-dist/doc/latex/circuitikz/circuitikzmanual.pdf

Thursday, January 19, 2012

Gnuplot - create high quality plot for publication

Open text editor and paste the following code and save the file as plot-gnu

#!/bin/bash

# Output file.pdf
file=trig

gnuplot << TOEND
# Setup output
set term postscript eps enhanced \
dashlength 4 \
linewidth 5 \
"Helvectica" 24\
color

set output "$file.eps"
#unset key
set yrange [-1.1:1.1]

set xlabel 'x'
set ylabel 'y'

# Format plot
p sin(x) t 'sin(x)'\
, cos(x) t 'cos(x)'

TOEND
epstopdf $file.eps
rm $file.eps



Make the code executable by running
chmod +x plot-gnu Run the code with
./plot-gnu You should now have a high quality plot in a file called trig.pdf A useful plot that shows all of the available (black and white) linetypes can be created with the following code. Follow the same steps as above. This code makes a file call linetypes.pdf. #!/bin/bash

# Output file.pdf
file=linetypes

gnuplot << TOEND
# Setup output
set term postscript eps enhanced \
dashlength 4 \
linewidth 5 \
"Helvectica" 24\
#color

set output "$file.eps"
unset key
set yrange [0:10]

set xlabel 'x'
set ylabel 'Linetype'

# Format plot
p 1 lt 1\
, 2 lt 2\
, 3 lt 3\
, 4 lt 4\
, 5 lt 5\
, 6 lt 6\
, 7 lt 7\
, 8 lt 8\
, 9 lt 9

TOEND
epstopdf $file.eps
rm $file.eps