TransWikia.com

Fit bounding box to gnuplot legend

TeX - LaTeX Asked by Gabriel Southern on January 3, 2021

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

Details:

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

One Answer

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.

Answered by Ian Thompson on January 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP