Graphics, Figures & TablesCompile errors when including epslatex graphics in Latex

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Steve06
Posts: 4
Joined: Sat Feb 06, 2010 4:14 pm

Compile errors when including epslatex graphics in Latex

Post by Steve06 »

Dear all,
I have installed gnuplot 4.4rc1 and made a simple plot to the epslatex terminal. This is my plot file: (inspired by an example in the book GNUPLOT in Action)

Code: Select all

set loadpath "C:/Program Files (x86)/gnuplot/bin/share/PostScript/"
set label 1 " '$\phi(x) = \frac{1}{\sqrt{2 \pi}} e^{-\frac{1}{2} x^2}$' " at 1.2,0.25
set label 2 '$\Phi(x) = \int_{-\infty}^x \phi(t) dt$' at 1.2,0.8
set key top left Left # Interchange line sample and explanation
unset xtics
set xtics ( '$-\pi/2$' -pi/2, '$0$' 0, '$\pi/2$' pi/2 )
plot [-3:3] exp(-0.5*x**2) /sqrt(2*pi) t '$\phi(x)$',norm(x) t '$\Phi(x)$'
set terminal epslatex
set o "epslatex.tex" # Name of output LaTeX file with extension!
replot
A .tex and a .eps file is then generated. I create another Latex file in the same folder, with the following content:

Code: Select all

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\section{The First Section}
This is a different document. We will include a \LaTeX\ file
containing the graph below.
\begin{figure}[h]
\begin{center}
\input{epslatex}
\end{center}
\caption{A Postscript file included in \LaTeX, with \LaTeX\ labels}
\end{figure}
And here is a second paragraph. The graph should have
been included before.
\section{The Second Section}
The second section really contains only a very short
text.
\end{document}
I use Texniccenter with Miktex 2.8 on Windows 7 64bit machine. I selected DVI output and when I tried to compile this file, 100 errors were found:
! Text line contains an invalid character.
l. 101
It is the same error a 100 hundred times. This error reports to the generated epslatex.tex file, and I check the line number 101, which contains nothing special but "\gplbacktext".

Can you please help me out on how to get this epslatex thing working?
Best,
Steve

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Compile errors when including epslatex graphics in Latex

Post by localghost »

It's been long ago since Gnuplot has been my favorite plot program. So I'm not of great help concerning that. Nowadays I rely on pgfplots. Look at the code below for an inspiration.

Code: Select all

\documentclass{minimal}
\usepackage{nicefrac}
\usepackage{pgfplots}

%\pgfplotsset{
%	every axis x label/.style={%
%		at={(0.5,0)},
%		below,
%		yshift=-8pt
%	},
%	every axis y label/.style={%
%		at={(0,0.5)},
%		xshift=-22pt,
%		rotate=90
%  }
%}

\begin{document}
	\begin{tikzpicture}%[font=\scriptsize]
		\begin{axis}[%
			width=10cm,height=7cm,
			legend style={at={(0.02,0.98)},anchor=north west,font=\scriptsize},
			xmin=-3.1416,xmax=3.1416,ymin=0,ymax=1,
			xtick={-3.1416,-1.5708,...,3.1416},
			xticklabels={$-\pi$,$-\nicefrac{\pi}{2}$,0,$\nicefrac{\pi}{2}$,$\pi$},
			ytick={0,0.2,...,1},
			yticklabel style={%
				/pgf/number format/.cd,
				fixed,
				fixed zerofill,
				precision=1,
			},
			xlabel={x axis},ylabel={y axis},
			extra description/.code={%
				\node[red,left] at (0.6,0.8) {$\displaystyle\Phi(x) = \int_{-\infty}^x \phi(t)\, dt$};
				\node[blue,right] at (0.6,0.4) {$\displaystyle\phi(x) = \frac{1}{\sqrt{2 \pi}}\, e^{-\frac{1}{2} x^2}$};
			}
		]
			\addplot[blue,smooth] gnuplot [domain=-pi:pi] {exp(-0.5*x**2)/sqrt(2*pi)};
%			\addlegendentry{$\phi(x)$};
			\addplot[red,smooth] gnuplot [domain=-pi:pi] {norm(x)};
%			\addlegendentry{$\Phi(x)$};
		\end{axis}
	\end{tikzpicture}
\end{document}
You can hardly get more consistency in your LaTeX documents than by using such internal solutions with provided graphics packages. This can similar be done with pstricks.


Best regards and welcome to the board
Thorsten
Steve06
Posts: 4
Joined: Sat Feb 06, 2010 4:14 pm

Re: Compile errors when including epslatex graphics in Latex

Post by Steve06 »

thank you for the recommendation localghost, I scrolled through the documentation but didn't find any graphs relying on a dataset, for example stock price time series.
Can data from an external text file be included in a pgfplots graph?

Otherwise, I'm still waiting for suggestions concerning my above problem.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Compile errors when including epslatex graphics in Latex

Post by localghost »

Steve06 wrote:[...] I scrolled through the documentation but didn't find any graphs relying on a dataset, for example stock price time series.
Can data from an external text file be included in a pgfplots graph? [...]
Obviously you browsed the manual very superficial. Of course you can plot datasets. Show an example of your diagrams, provide the according dataset and we'll see what we can do. Remember that the package is only for plotting, not for manipulating datasets.
Steve06
Posts: 4
Joined: Sat Feb 06, 2010 4:14 pm

Re: Compile errors when including epslatex graphics in Latex

Post by Steve06 »

i solved my problem by myself:

at the end of the gnuplot script, you must "release" the output file by stipulating "set output". this it it. now the compilation works.

back to your suggestion, ghost:
i uploaded a graph out of latex (as gif snapshot) and accompanying data.
I'm curious to see what you can make out of it.
Attachments
graph.zip
(41.7 KiB) Downloaded 247 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Compile errors when including epslatex graphics in Latex

Post by localghost »

At first I have to say that I had to supplement the data file by a column with the running number. The reason is that pgfplots at the moment seems not to support custom tick labels controlled by external files. (And if it does, I was not able to find out how on the quick.) So I opened OpenOffice.org (OOo) and exported the result to a CSV file. The source code as well as the modified data file can be found in the attachment. The final output is in a separate attachment for those who are interested only in that. I think the chart looks quite nice.
Attachments
stockmarket.zip
Source code and modified data file.
(20.48 KiB) Downloaded 188 times
stockmarket.pdf
The final output.
(101.42 KiB) Downloaded 273 times
Steve06
Posts: 4
Joined: Sat Feb 06, 2010 4:14 pm

Re: Compile errors when including epslatex graphics in Latex

Post by Steve06 »

thank you.
really looks worth for me to take a closer look at.

the advantage of gnuplot from my perspective is: once you learn how to use it, you can use it for a lot of applications, for example websites and other stuff, and not only latex documents.

but for quick graphs in latex, pgfplot looks just fine.
amos
Posts: 2
Joined: Sun Apr 10, 2011 9:48 am

Re: Compile errors when including epslatex graphics in Latex

Post by amos »

Hello Stev06,

Can you explain me exactly how did you solve the problem? I'm using exactly the same codes as in "GNUplot in Action", but i still get the errors.

Thank you so much,

Alejandro
amos
Posts: 2
Joined: Sun Apr 10, 2011 9:48 am

Re: Compile errors when including epslatex graphics in Latex

Post by amos »

Oh yes, sure, you told the answer: i should stipulate "set output" at the end of the script. Now however, after compilation, Miktex shows me several errors (13 in the case of the textbook example); i think these shouldn't be normal.

Despite this, Miktex seems to create the ps file correctly, but other sofwtare (like Texmaker) doesn't. I'm submitting a latex file to a journal, and i don't want to send a file with errors. Maybe at this point you should know what the problem is. Can you help me, please?

Best,

Alejandro
Post Reply