I am trying to get somewhat consistent output between eps and pdf terminals in gnuplot. The trouble is that they seem to understand size units differently; the same specified size in inches will result in a much larger font size for the pdf output:
set terminal postscript eps enhanced colour size 10in,8in font 'Arial-Bold,14'
set output 'my_eps.eps'
set title 'My plot'
plot sin(x) notitle
set terminal pdfcairo size 10in,8in font 'Arial-Bold,14'
set output 'my_pdf.pdf'
replot
The text in the .pdf is much larger and the graph is cramped. However, if I change the size units of the eps to cm:
set terminal postscript eps enhanced colour size 10cm,8cm font 'Arial-Bold,14'
########
set output 'my_eps.eps'
set title 'My plot'
plot sin(x) notitle
set terminal pdfcairo size 10in,8in font 'Arial-Bold,14'
set output 'my_pdf.pdf'
replot
The outputs look the same (to within some margin errors) with the wrong units. Is this a coincidence? What's going on here?
This was tested for Gnuplot 4.4 (patchlevel 3) Ubuntu 11.10.
(I know I could use some utility to convert between eps and pdf so they would be the same, but I'd like to understand what's going on in gnuplot.)
For example, to export Gnuplot output to PDF format, first install ps2pdf which is contained in Ghostscript package. Then redirect Gnuplot's poscript output to PDF format.
With the two plots in the same unit system, this behavior is expected -- although maybe not well/accurately documented. (from help post
)
In `eps` mode the whole plot, including the fonts, is reduced to half of
the default size.
Since you specified a size explicitly, that part sticks, but the fonts are still reduced in size by a factor of 2 on the eps
plot even if you specify a font explicitly (I don't know why this is, but it's always been that way -- I've always considered it a bug in the documentation at least ... ).
As far as switching the units to centimeters -- I'm not at my computer with the cairo
terminals enabled, so I can't check right now ... but that seems odd (to me). Is it perhaps because the conversion to centimeters from inches is about a factor of 2 which makes them look so similar? (e.g. your fonts are half the size while your plot is 1/2.54 the size)
To achieve terminal independence, I suppose you could write it up in a function (CURRENTLY UNTESTED):
fontsize(x)=((GPVAL_TERM eq 'postscript') && \
(strstrt(GPVAL_TERMOPTIONS,"eps")!=0)) ? x*2 : x
set term post eps enh size 10in,8in
set termoption font "Arial,".fontsize(7)
set output "Hello.eps"
plot sin(x)
set term pdfcairo enh size 10in,8in
set termoption font "Arial,".fontsize(7)
set output "Hello.pdf"
plot sin(x)
Make sure you only pass integers to fontsize -- integers get promoted to strings when doing string concatenation.
EDIT
After digging a little further, it appears that the cairo library is taking some liberties and embedding a (similar) font that you didn't ask for.
running pdffonts myfile.pdf
-- Note that you get the fontname just by strings myfile.pdf | grep FontName
:
name type emb sub uni object ID
-------------------- ------------ --- --- --- ------ --
LiberationSansBold CID TrueType yes no yes 5 0
whereas the postscript just contains the font name (not embedded) which gets translated by the ps viewer as the closest thing it can find to the requested font (It [probably] substitutes a font you didn't ask for also). So, to achieve true terminal independence (between these two terminals), you'd need to find the fontfile that was embedded in the pdf and then set postscript eps enh color fontfile add "<fontfile>"
to embed the same fontfile in both the pdf and the postscript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With