Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Consistent figure sizes with gnuplot

Tags:

gnuplot

I am trying to make figures with gnuplot that will be included in a latex document. I want all figures to have the same dimensions and font size. To achieve it I found that I should specify the size of the figure in advance, which I do as such:

set terminal postscript eps size 3.4004,2.104 enhanced color

However, the resulting .eps figures have a lot of whitespace around them so I use the fixbb script to remove all unnecessary space. This changes the final size of the figure as well, which wouldn't be a problem as long as it is consistent. However, the amount of whitespace seems to vary from figure to figure, so my final figures have all different sizes. This seems especially a problem with 3D plots.

Is there a way to make the size consistent while removing all unnecessary white space? In matplotlib there is the plt.tight_layout() command which does exactly that.

like image 556
user1830663 Avatar asked Apr 27 '26 01:04

user1830663


1 Answers

If by fixing the size of the figure you refer to the rectangle within which the data is plotted, you can set the margins manually. What I usually do for figures I put on my papers is use the epslatex terminal with the desired size and font, then set the margins, and then compile to pdf followed by a cropping to remove the white space. Example

set term epslatex color size 3.5,2.5 font 6
set output "gnuplot.eps"

set lmargin at screen 0.2
set rmargin at screen 0.98
set tmargin at screen 0.98
set bmargin at screen 0.1

plot sin(x) title '$\sin (x)$'

I embed this into a .tex file (which I call plot.tex):

\documentclass{article}

\usepackage[papersize={100cm,100cm}]{geometry}

\usepackage{graphicx}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[mathcal]{euscript}

\begin{document}

\thispagestyle{empty}

\include{gnuplot}

\end{document}

And run the following:

pdflatex plot.tex
pdfcrop plot.pdf

You will have a plot-crop.pdf with no white space around. Using different modifications of the above you can very precisely modify the size of your graph.

enter image description here

Finally, note that the epslatex terminal also allows the standalone option to avoid needing an external latex document to wrap your graph.

like image 169
Miguel Avatar answered May 01 '26 02:05

Miguel