Tuesday, November 17, 2009

Fixing EPS bounding box automatically

Writing a paper. Time to put Matlab or Scilab plots in. You go file->
save as EPS to include into Latex.
Surprise: Matlab has an awful bounding box space around the figure.
You want to autocrop it but its a vector graphics format,
so you can't use mogrify -trim +repage <filename> as you would normally
do with an image.

Solution: epstool. It does an autocrop for the EPS file:

epstool --copy --bbox input.eps output.eps

and your final plot will still look crisp.

Another option: save as PDF in matlab. Then use ImageMagick's convert to convert it to eps:

convert file.pdf file.eps

this will keep the vector graphics intact (at least in recent versions of ImageMagick).

Of course, you can always use pdflatex instead and avoid EPS altogether.

10 comments:

Anonymous said...

oh man thanks! epstool is a godsent! had been manually editing the bounding box before reading your blog.

Thanks again!

Anonymous said...

Nice post and this post helped me alot in my college assignement. Gratefulness you seeking your information.

ignamv said...

Thanks, your post was very useful.

I did a short script to cut eps files:

#!/bin/sh

mv $1 temp
epstool --copy --bbox temp $1
rm temp

Nishan Singh said...

Than you very much! This just saved me a lot of reading and trial and errors. I was having trouble with gnuplot's postscript terminal leaving a lot of blank space.This was a big help! Thanks again!

Anonymous said...

thank you very much, this really helped me!

Anonymous said...

Great help! Than you very much!

vroom_hunters said...

Thats so much ..... been swapping formats and programs so far

Syphodyas said...

Thank you so much! I had been manually cutting then until now.

Cheers

Syphodyas said...

Thank you so much! I had been manually cutting then until now.

Cheers

Anonymous said...

many many thanks! this tool really works and is well documented about the purpose!