pdflatex and gnuplot's epslatex

I'm having some trouble trying to use gnuplot's epslatex terminal in a tex document to be compiled with pdflatex. The figure appears too big in the final pdf, and the axis' tics are not in math mode, even though I used set format '$%g$'. I have been playing around with the plot's size too, but I achieved pretty much nothing.

Here is the result using png:

And here the result using epslatex:

Here is a minimal working example for the tex file (commented part to obtain the png version):

\documentclass[10pt,a4paper,twoside,pdf]{article}
\usepackage{graphicx}

\begin{document}

\begin{figure}[t]
\centering
%\includegraphics[width=0.8\textwidth]{figure.png}
\input{figure.tex}
\caption{Some text.}
\label{something}
\end{figure}

\end{document}


And here the gnuplot script (again, commented part for png):

set xlabel 'x label'
set ylabel 'y label'

f(x)=a*(1-exp(-k*x))

fit f(x) 'data.dat' via a, k

#set term pngcairo size 2000,1500
#set termoption font ',35'
#set output 'figure.png'
set term epslatex size 10cm,6cm
set output 'figure.tex'
set format '$%g$'
unset key
set samples 10000
set xrange [0:11]

plot 'data.dat' w p pt 7 ps 4 lc rgb 'black', f(x) lw 4 lc rgb 'red'


Also, the file data.dat, for completeness' sake:

1   1
2   1.64
3   2.4
5   3.28
10  5.6.


I don't know if this question should be here because it may be a gnuplot issue rather than a pdflatex issue, but anyway, help will be appreciated. Thanks! :)

• Why not just use pgfplots instead? – JPi Jul 19 '17 at 14:03
• I didn't know this one, thanks for suggesting it! I'll give it a try, although I'd still want to find out how to use epslatex. – manugutito Jul 19 '17 at 14:12
• Are you aware of the TikZ terminal? texample.net/tikz/examples/gnuplot-tikz-terminal – Alan Jul 19 '17 at 15:00
• It worked here right out of the box with epslatex. You can check the size by putting \rule{10cm}{1pt}\\  before \input{figure.tex}. The size includes the space for the label and some space around, not just the graph. Plot file: set format only sets the format for the numbers on the axis. This works and can be checked with e.g. set format '$%ga$'. To get the labels in math mode you can use e.g. set xlabel '$x$ label. Caution: if the png file still exists, it will be included instead of the eps file. You can also use set term cairolatex pdf size ... to get a pdf instead of eps. – Mike Jul 19 '17 at 21:54
• Alright, I looked at the tex file from gnuplot and I figured it out. The problem is that both the eps and the png file have the same name, and the tex file created by gnuplot does \includegraphics{figure} without specifying an extension. If I either erase the png or modify the tex to \includegraphics{figure.eps}, it works like a charm. – manugutito Jul 20 '17 at 10:17

As @Mike stated in the comments, if the png file generated by gnuplot is at the folder when pdflatex is run, it will use the png file instead of the eps.

I am writing this only so I can mark the question as closed.

\input{figure.tex}

\resizebox{0.9\textwidth}{!}{\input{figure.tex}}

• That was not the problem, although I can see why you would say this. My problem was that I used pngcairo as gnuplot's output before trying epslatex. The tex file generated by epslatex specifies no extension in the \includegraphics statement, so it will use the existing png instead of the eps file generated by gnuplot for some reason. – manugutito Nov 2 '17 at 20:20