Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to reduce this whitespace, but seem to be at a limit at how much I can (GNUPLOT)

Tags:

latex

gnuplot

I'm producing contour plots on gnuplot and outputting eps files which I then run in latex. It is four contour plots, and I need them all on the same level of my page. I am close but;

enter image description here

You can see the white space of the three remaining plots takes up some room, if they were removed it would surely all fit on one line (all pictures on the same level). This is an example of what my gnuplot code (for the ones that don't have a y-axis);

 reset
 set size 0.38, 1

set terminal epslatex
set out 'finalpolar2.tex'
set termoption dash


#set title istitle;
set font "20"
unset xlabel
unset ylabel
set format y ""
set ylabel offset 1.5;
set palette model HSV rgbformulae 7,5,15
set contour;
set view map;
unset surface;
set cntrparam levels 8;
set isosamples 50;
unset key;
set size ratio 2
set xtics 0,0.5,40
set cbtics 0,0.02,40
set cbtics offset -1;
splot 'loop_final.txt' w l lw 5 palette notitle
  set out

(Some of those things are irrelevant, they are copy/pasted from an older code). I basically did "set size 0.38,1" as low as I could before the image itself started getting shortened. The problem stems in the whitespace of the y-axis that doesn't exist since I removed it. Can anyone help?

like image 443
AntiElephant Avatar asked May 11 '14 18:05

AntiElephant


2 Answers

This is a common problem with the bounding boxes generated by gnuplot's eps terminals.* There are several approaches you could take.

set margin

You can manually set margins in gnuplot with the set [rltb]margin commands. For example, to set the left margin to zero, you can add

set lmargin 0

to your scripts.

eps2eps

Assuming you are on *nix/Mac OS, you can use the eps2eps utility to "convert" the eps to another eps, which usually fixes the boundingbox on the way. I created a script I call fixbb (not to be confused with the one hidden on the gnuplot website) which runs this command:

eps2eps $1 $1.bak && mv $1.bak $1

and that usually does the trick for me.

use a different terminal

If it is not important to have LaTeX formatting in your figures, it works to use pdf[cairo] or png[cairo] and then include those graphics in your document.

adjust the figure in your LaTeX document

You mention that all the figures would fit on one line if only gnuplot would make smaller margins, but it sounds like you are trying to adjust the size of your gnuplot output, when you can also modify things from within LaTeX. For example, to make the figures a little smaller use a smaller width parameter in \includegraphics:

\includegraphics[width=0.2\textwidth]{myeps.eps}

You can also crop images with \includegraphics.

*There are two issues here: (i) gnuplot tends to give generous margins by default even on sides of plots where there are no axes/labels, and (ii) this is compounded by the fact that gnuplot can make wonky bounding boxes for eps files.

like image 114
andyras Avatar answered Nov 15 '22 09:11

andyras


There is a common misunderstanding of the set size option. This does not change the image size (canvas size), but only the size of the plot with respect to the whole image. In order to change the size of the image, use the size option of set terminal, e.g.

set terminal epslatex size 4cm,6cm

With set size the automatically layouted plot size is used as reference for the scaling. And this 'original' size depends on the {x|y|x2|y2}label and the respective tics. So, with exactly the same settings, the plot area of your first image will have a different width, because it has a ylabel and ytics.

I would also suggest you not to change the width of the figures when including them (e.g. with \includegraphics[width...] because that also change the font size and the line width etc.

Unfortunately, there is no best way to get what you want.

In my thesis I layouted such images completely in gnuplot including the short subcaptions. So I gave up on referencing every subfigure with \ref, but had nicely composed pictures.

If you want to create the subfigure captions inside your main document and reference them, I would suggest you to use the same canvas size (set terminal epslatex size ...) for every subfigure and also the same fixed margins using set lmargin at screen 0.2 etc. and then adapt the margin settings and terminal size such that the four cropped images fit on a single line.

You could also use a single script for the four pictures, so you have only one place to change the settings.

I used to use epstool --bbox --copy --output new.eps old.eps to crop the images, but that doesn't work any more, the margins are wrong (don't know if its a problem with a certain gs version). But ps2eps -f -B works fine for me. Again, for my thesis I used pdflatex anyway so I used the epslatex terminal but converted to pdf and then cropped that with pdfcrop.

You see, that there are many ways to get the same result :)

like image 37
Christoph Avatar answered Nov 15 '22 09:11

Christoph