Summary: Is there a way to automatically reduce the bounding box of an eps file to only fit displayed text?


A while ago I asked a question about combining multiple gnuplot graphs into a single figure. I am trying to do something similar, but this time I also want to only have one legend for all the figures. To accomplish this I want to generate a graph with only the legend, and then place that in the appropriate place in the figure as a subfigure.

I am able to generate a gnuplot with only the legend by turning off everything else and setting the plot range to a section that does not display any data using these commands:

unset border
unset xtics
unset ytics
unset title
unset xlabel
unset ylabel
set xrange[-50:-10]
set yrange[-50:-10]

This gives me a graph with only the key set. The problem is that the bounding box still contains the space for the actual graph (shown below). What I would like to do is crop this to something that only contains the key so that I can combine that easily with the other plots (as described in the answer to my other question).

I am able to get something closer to what I want by manually editing the bounding box, but I would prefer a fully scripted solution if possible. I've tried a few things but haven't gotten it working yet so I thought I would ask here since my earlier question received a very helpful answer.

Initial eps file: enter image description here

Desired eps file (after editing bounding box): enter image description here

  • 2
    An untested idea: convert EPS to PDF, use the pdfcrop tool, convert it back from PDF to EPS. Or try GhostScript and use the bbox device?
    – Malipivo
    Mar 31, 2015 at 16:53
  • @Malipivo thanks pdfcrop does what I need. Mar 31, 2015 at 17:13
  • @Malipivo care to answer? Apr 19, 2015 at 1:55
  • @Paul Gessler Please, go ahead, if you can. I'd love to answer, but I cannot do it these days. The OP's question is related to tex.stackexchange.com/questions/151646/…
    – Malipivo
    Apr 19, 2015 at 4:42

1 Answer 1


One trick to deal with circumstances in which gnuplot creates an incorrect bounding box is to output to postscript (not encapsulated) and then make a system call to ps2eps to generate a corrected file. An example, using set size ratio to create the bad box:

set term postscript color
set size ratio 2
set output "wrong_bb.ps"
plot x**2
!ps2eps --ignoreBB -rotate=+ -f wrong_bb.ps

You may need to play around with the rotate option: + means 90 degrees clockwise, - means 90 degrees anticlockwise and ^ means 180 degrees.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .