0

I use the following gnuplot script in order to plot a data file

reset
unset key
set size 1,1

set xrange [-10.1:11]
set yrange [-45:45]

set xlabel 'x'
set lmargin 6
set label 1 "~x{0.7.}" font "Helvetica, 20" at graph -0.1, graph 0.5

set xtics 2
set ytics 15

set mxtics 5
set mytics 5

plot "pss_data.dat" u 1:2 w dots lc rgb 'black'

set term postscript eps enhanced "Helvetica" 20 size 7in, 5in
set output 'plot.eps'
replot

reset
set terminal windows

quit

The exported .eps file is the following.

enter image description here

Well, in fact this is the corresponding .pdf file using Adobe Acrobat XI in order to make the conversion. However, the .pdf output contains not only the plot but all the unwanted black area above it! In an attempt to get rid off the white area I used the command line

epstopdf plot.eps

The output is the following

enter image description here

Now, the white area has been removed but the label at the y axis is also missing!

Any ideas? I want to have in a .pdf file only the plot (without the above white area) but with the label at the y axis.

Many thanks in advance.

Vaggelis_Z
  • 221
  • 3
  • 15
  • As a side note -- gnuplot has terminals which (depending on your installation) could be used instead. type `set terminal` in the interactive gnuplot prompt to see a list. These days, the best option is `pdfcairo`, but the old `pdf` terminal should also do the trick if your gnuplot install supports it. – mgilson Feb 04 '13 at 14:39
  • @mgilson My `gnuplot` version supports both `pdf` and `pdfcairo` terminals. However, in both of them the y label is still missing from the plot. The above white area has been removed but I cannot retain the y label ... – Vaggelis_Z Feb 04 '13 at 15:08
  • Is there a reason for the explicit `set lmargin 6` in your script -- rather than relying on gnuplot's autoscaling? I'm guessing that is cropping the label off the plot, but somehow abode resurrected it when exporting. – mgilson Feb 04 '13 at 15:12
  • @mgilson I removed the option `set lmargin 6` but still the same. – Vaggelis_Z Feb 04 '13 at 15:26
  • finally, why are you using `set label 1 ... at graph ...` instead of `set ylabel`? – mgilson Feb 04 '13 at 15:46
  • @mgilson I use this approach in order to rotate the ylabel making it "parallel" to the xlabel. And as far as I know, this is the only feasible way to rotate the ylabel in `gnuplot`. – Vaggelis_Z Feb 04 '13 at 16:16
  • did you try `set ylabel "whatever" rotate by 0`? – mgilson Feb 04 '13 at 16:17
  • @mgilson Thank you very much! I did not know this option. It's working like a charm. Also when using the epstopdf command, I can remove the unwanted white area above the plot but now the `ylabel` its not affected! – Vaggelis_Z Feb 04 '13 at 16:28
  • @mgilson By the way, I use gnuplot 4.6 patchlevel 0 under Win XP. Is patchlevel 1 available? – Vaggelis_Z Feb 04 '13 at 16:30
  • No idea -- I don't use windows :-P – mgilson Feb 04 '13 at 16:31
  • I've looked at their sourceforge page and can't find 4.6.1 for windows there ... It might just be an oversight on the part of the developers ... – mgilson Feb 04 '13 at 16:36

2 Answers2

2

Your bounding box may be incorrectly set. You can try using epstool on the eps you create:

epstool --bbox myeps.eps myneweps.eps

That should calculate the bounding box correctly, but give you a margin of zero. If you can't/don't want to install it, try adjusting the bounding box manually. There is a line near the top of the .eps file which looks like this:

%%BoundingBox: 50 50 554 770

The four numbers are the y offset, x offset, y max and x max of the output (in terms of margins you can think of them as top, left, bottom, right). You can try decreasing the second number (increasing the left margin) to see if that reveals your y axis label.

andyras
  • 15,542
  • 6
  • 55
  • 77
  • I installed `epstool`, and after inserting the command epstool --bbox plot.eps plot2.eps I got the message "No command specified." Run epstool --help for more details. – Vaggelis_Z Feb 04 '13 at 15:23
  • After a little digging, I discovered that the working command is indeed > epstool --copy --bbox input.eps output.eps Then, using epstopdf output.eps everything is OK! – Vaggelis_Z Feb 04 '13 at 15:43
1

I would avoid the conversion all together by using one of gnuplot's pdf terminals (I like pdfcairo) and just use ylabel instead of set label 1 ... at graph.... Here's a simple script that you can modify for your purposes:

set term pdfcairo enhanced font "Helvetica,20"
set output "test.pdf"
set ylabel "~x{0.7.}" rotate by 0  #default rotation is 90
set xlabel "x"
plot sin(x)

Ultimately, what is happening with your script is that gnuplot is putting the label off of the viewable canvas. Some reason adobe still puts the label on the (converted) output, but I would assert that they are wrong in this case -- (they're essentially ignoring your bounding box). Of course, you could move/adjust the bounding box as suggested in the answer by andyras -- but I would argue that is a pretty hacky solution.

mgilson
  • 300,191
  • 65
  • 633
  • 696