1

I wrote the code for a plot in gnuplot and set the output using epslatex terminal as follows:

set term epslatex color
set output "test.tex"

set multiplot layout 2,3 columnsfirst margins 0.1,0.9,0.1,0.9 spacing 0.07,0.0

unset key

set format x " "
#set xtic 400
#set ytic 100
#unset xlabel

set yrange [0:150]

set title "D1"


plot [0:10] x**2 lc -1 lw 2 with lines , [0:5] x**3 lc rgb "#FF4433" pt 5 ps 0.7

#unset key
unset format x

unset title


plot [0:10] x**2 lc -1 lw 2 with lines , [0:5] x**3 lc rgb "#FF4433" pt 5 ps 0.7



set format x " "


set title "D2"


plot [0:10] x**2 lc -1 lw 2 with lines , [0:5] x**3 lc rgb "#FF4433" pt 5 ps 0.7

unset format x


unset title
 
 
plot [0:10] x**2 lc -1 lw 2 with lines , [0:5] x**3 lc rgb "#FF4433" pt 5 ps 0.7



set format x " "


set title "D3"


plot [0:10] x**2 lc -1 lw 2 with lines , [0:5] x**3 lc rgb "#FF4433" pt 5 ps 0.7

unset format x
unset title

set label 1 "$x $"  at screen 0.47,0.04 
set label 2 "$f(x)$"  at screen 0.05,0.43 rotate by 90 
set label 3 "$ (a)\\; NK $" at -25.2696,239.562
set label 4 "$ (b) \\; NKH \\Delta $" at -25.4174,102,370

set key at -22.5856,276.937 box

plot [0:10] x**2 title "$ x^2 $" lc -1 lw 2 with lines , [0:5] x**3 title "$ x^3 $" lc rgb "#FF4433" pt 5 ps 0.7

unset label 1
unset label 2
unset label 3
unset label 4

unset multiplot

set output

When setting output using set terminal jpeg size 1800,900 , I am getting the following: plot1

But after setting the output using epslatex , I am getting a distorted image as follows: plot2

How do I reconcile the outputs and make the later look like the former?

The resulting ".tex" file from the gnuplot code is as follows:

% GNUPLOT: LaTeX picture with Postscript
\begingroup
  \makeatletter
  \providecommand\color[2][]{%
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package color not loaded in conjunction with
      terminal option `colourtext'%
    }{See the gnuplot documentation for explanation.%
    }{Either use 'blacktext' in gnuplot or load the package
      color.sty in LaTeX.}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\includegraphics[2][]{%
    \GenericError{(gnuplot) \space\space\space\@spaces}{%
      Package graphicx or graphics not loaded%
    }{See the gnuplot documentation for explanation.%
    }{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
    \renewcommand\includegraphics[2][]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \@ifundefined{ifGPcolor}{%
    \newif\ifGPcolor
    \GPcolorfalse
  }{}%
  \@ifundefined{ifGPblacktext}{%
    \newif\ifGPblacktext
    \GPblacktexttrue
  }{}%
  % define a \g@addto@macro without @ in the name:
  \let\gplgaddtomacro\g@addto@macro
  % define empty templates for all commands taking text:
  \gdef\gplbacktext{}%
  \gdef\gplfronttext{}%
  \makeatother
  \ifGPblacktext
    % no textcolor at all
    \def\colorrgb#1{}%
    \def\colorgray#1{}%
  \else
    % gray or color?
    \ifGPcolor
      \def\colorrgb#1{\color[rgb]{#1}}%
      \def\colorgray#1{\color[gray]{#1}}%
      \expandafter\def\csname LTw\endcsname{\color{white}}%
      \expandafter\def\csname LTb\endcsname{\color{black}}%
      \expandafter\def\csname LTa\endcsname{\color{black}}%
      \expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
      \expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
      \expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
      \expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
      \expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
      \expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
      \expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
      \expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
      \expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
    \else
      % gray
      \def\colorrgb#1{\color{black}}%
      \def\colorgray#1{\color[gray]{#1}}%
      \expandafter\def\csname LTw\endcsname{\color{white}}%
      \expandafter\def\csname LTb\endcsname{\color{black}}%
      \expandafter\def\csname LTa\endcsname{\color{black}}%
      \expandafter\def\csname LT0\endcsname{\color{black}}%
      \expandafter\def\csname LT1\endcsname{\color{black}}%
      \expandafter\def\csname LT2\endcsname{\color{black}}%
      \expandafter\def\csname LT3\endcsname{\color{black}}%
      \expandafter\def\csname LT4\endcsname{\color{black}}%
      \expandafter\def\csname LT5\endcsname{\color{black}}%
      \expandafter\def\csname LT6\endcsname{\color{black}}%
      \expandafter\def\csname LT7\endcsname{\color{black}}%
      \expandafter\def\csname LT8\endcsname{\color{black}}%
    \fi
  \fi
    \setlength{\unitlength}{0.0500bp}%
    \ifx\gptboxheight\undefined%
      \newlength{\gptboxheight}%
      \newlength{\gptboxwidth}%
      \newsavebox{\gptboxtext}%
    \fi%
    \setlength{\fboxrule}{0.5pt}%
    \setlength{\fboxsep}{1pt}%
\begin{picture}(7200.00,5040.00)%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(588,2520){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(588,3863){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(720,2300){\makebox(0,0){\strut{} }}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%%
      \put(1511,4865){\makebox(0,0){\strut{}D1}}%
    }%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(588,504){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(588,1847){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(720,284){\makebox(0,0){\strut{}$0$}}%
    }%
    \gplgaddtomacro\gplfronttext{%
    }%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(2676,2520){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(2676,3863){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(2808,2300){\makebox(0,0){\strut{} }}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%%
      \put(3599,4865){\makebox(0,0){\strut{}D2}}%
    }%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(2676,504){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(2676,1847){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(2808,284){\makebox(0,0){\strut{}$0$}}%
    }%
    \gplgaddtomacro\gplfronttext{%
    }%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(4764,2520){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(4764,3863){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(4896,2300){\makebox(0,0){\strut{} }}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%%
      \put(5687,4865){\makebox(0,0){\strut{}D3}}%
    }%
    \gplgaddtomacro\gplbacktext{%
      \csname LTb\endcsname%%
      \put(4764,504){\makebox(0,0)[r]{\strut{}$0$}}%
      \put(4764,1847){\makebox(0,0)[r]{\strut{}$100$}}%
      \put(4896,284){\makebox(0,0){\strut{}$0$}}%
      \put(3384,202){\makebox(0,0)[l]{\strut{}$x $}}%
      \put(360,2167){\rotatebox{90}{\makebox(0,0)[l]{\strut{}$f(x)$}}}%
      \put(896,3722){\makebox(0,0)[l]{\strut{}$ (a)\; NK $}}%
      \put(872,1874){\makebox(0,0)[l]{\strut{}$ (b) \; NKH \Delta $}}%
    }%
    \gplgaddtomacro\gplfronttext{%
      \csname LTb\endcsname%%
      \put(466,4114){\makebox(0,0)[r]{\strut{}$ x^2 $}}%
      \csname LTb\endcsname%%
      \put(466,3894){\makebox(0,0)[r]{\strut{}$ x^3 $}}%
    }%
    \gplbacktext
    \put(0,0){\includegraphics{test}}%
    \gplfronttext
  \end{picture}%
\endgroup

And the latex code used to plot it is:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}

\title{plot}
\author{anon }
\date{February 2022}


\begin{document}

\maketitle

\section{Introduction}

\begin{figure}[h]
    \centering
    \input{test.tex}
    \caption{Caption}
    \label{fig:my_label}
\end{figure}


\end{document}

The ".eps" file is available here : test.eps

D.K.
  • 15
  • 3
  • Can you share both the resulting files from your script as well as a [mre] of your latex file? – samcarter_is_at_topanswers.xyz Feb 21 '22 at 21:42
  • @samcarter_is_at_topanswers.xyz I have included those now. – D.K. Feb 22 '22 at 14:15
  • Can you also share the image `test`? – samcarter_is_at_topanswers.xyz Feb 22 '22 at 14:23
  • you mean the .eps file that I get? @samcarter_is_at_topanswers.xyz – D.K. Feb 22 '22 at 14:28
  • yes, please. Github, dropbox, etc might be helpful to share it – samcarter_is_at_topanswers.xyz Feb 22 '22 at 14:30
  • 1
    @D.K. with the jpeg terminal you explicitely set `set terminal jpeg size 1800,900`. I would assume if you don't explicitly set the terminal size of the epslatex terminal, the default size will be taken which probably has a different aspect ratio, hence leading to a "distorted" image. Just a thought. – theozh Feb 22 '22 at 14:35
  • @samcarter_is_at_topanswers.xyz I have edited that in too – D.K. Feb 22 '22 at 14:56
  • @theozh I tried to set the same size in epslatex terminal but while compiling in overleaf the picture doesn't show and an error occurs "Float too large for page". – D.K. Feb 22 '22 at 14:57
  • @D.K. Then make the size smaller, but with the same aspect ratio – samcarter_is_at_topanswers.xyz Feb 22 '22 at 15:28
  • unfortunately the picture environment does not allow to set the unit lengths separately, like tikz does. The closest one can get to fixing this from the latex site is probably `\scalebox{1}[0.75]{\input{test.tex}}`, but the font is terrible distorted... – samcarter_is_at_topanswers.xyz Feb 22 '22 at 15:30
  • @D.K. to what exactly have you set the epslatex terminal size? `set term epslatex color size 1800,900`? Default units are inches. So, this will be interpreted as 1800 inches x 900 inches, maybe a bit large. Maybe try e.g. `set term epslatex color size 18cm,9cm`. – theozh Feb 22 '22 at 15:40
  • @theozh I tried the size 21 cm, 9 cm and I am getting output as follows: [link](https://filedropper.com/d/s/J4MM5cptwuxzbYqaQWtj3JVRhaNaSz) . The image seems to go out of bounds in the right side. How do I shift it more towards the left? – D.K. Feb 22 '22 at 16:10
  • @D.K. The default textwidth in your document is about 12cm. Make it smaller! – samcarter_is_at_topanswers.xyz Feb 22 '22 at 20:12
  • @samcarter_is_at_topanswers.xyz changing the font size in gnuplot code does not seem to have the desired effect with setting the output in latex. The words seem to change position. – D.K. Feb 23 '22 at 14:16

1 Answers1

0

[original was answer based on a guess shown to be incorrect by the uploaded sample code]

To get a more complete answer I think you need to show the LaTeX code at the site of inclusion.

Amended answer

As theozh points out, you need to use a consistent aspect ratio. If I modify your original script to use

set term epslatex color size 6in, 3in

and modify the top of your .tex script to say

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\pagestyle{empty}
\usepackage{xcolor}

leaving all else the same as you show, I get the figure below. You have used a mixture of screen coordinates and plot coordinates to position the text labels. I'm not sure which of those is better, but mixing them may not be a good idea.

enter image description here

Ethan
  • 13,715
  • 2
  • 12
  • 21
  • I have included that now in the question. – D.K. Feb 22 '22 at 14:15
  • Can these abel adjustments be done directly from the latex code without changing the gnuplot code? Also, can the key box dimension be changed from the latex code itself? – D.K. Feb 23 '22 at 14:18