Discussion:
Plot to PDF
Torquil Macdonald Sørensen
2009-07-09 22:50:00 UTC
Permalink
Hi!

When I plot to pdf in octave, the page format turns out wrong. The resulting PDF
looks like an A4 page, even though the actual plot is wider than its height
(standard format). I'm using octave 3.2 and the newest gnuplot development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo terminal.

The command I have tried when plotting to pdf in octave is:

fplot(blablabla...)
print("plot.pdf")

It works, apart from that page format issue. Anyone know how to do it right? I'm
using the octave3.2 from Debian Sid.

Thanks
Torquil Sørensen
Ben Abbott
2009-07-10 00:27:26 UTC
Permalink
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The resulting PDF
looks like an A4 page, even though the actual plot is wider than its height
(standard format). I'm using octave 3.2 and the newest gnuplot
development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil Sørensen
It's not clear to me what you are seeing, or what you expect to see.
So I'll explain what should happen and you can comment.

Both pdf an postscript output respect the papersize and paperposition
properties.

The default are

papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];

The resulting pdf/postscript output should (approximately) fill a 8x6
in box centered on a page of 8.5x11 inches.

If this is what you see, then all is working correctly.

If you'd like to produce a pdf to import into a LaTeX document (or a
figure for a similar purpose), then try

set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf

Ben
Torquil Macdonald Sørensen
2009-07-10 01:10:36 UTC
Permalink
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The resulting PDF
looks like an A4 page, even though the actual plot is wider than its height
(standard format). I'm using octave 3.2 and the newest gnuplot development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil Sørensen
It's not clear to me what you are seeing, or what you expect to see. So
I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a 8x6 in
box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document (or a
figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf
Ben
Thanks Ben, I will try to explain more thoroughly and provide some files. When
using the plot command, a window appears, with certain dimensions. This window
is a bit wider than it is tall. I would like the PDF to have the same dimensions.

When I use the print command to obtain an EPS file, the EPS has the same aspect
ratio as this window. When printing to PDF, there is lots of extra white space
above and below the plot. So the result is not the same when printing to EPS and
PDF. So printing to EPS gives the desired result.

(Btw, I assume you meant "print test.pdf", not "plot plot.pdf" in your example
code above)

I have uploaded and EPS and a PDF so that the difference can be seen:

* EPS example:

plot (1:10)
print plot.eps

Result: http://folk.uio.no/tmac/plot.eps

* PDF example:

plot (1:10)
print plot.pdf

Result: http://folk.uio.no/tmac/plot.pdf

The EPS has the format that I want, and which is the same as the plot window
displayed by octave after the plot command.

The "set(gcf..." you included in the above has the following effect:

EPS case: It affects the aspect ratio of the graphic, as well as the paper
format/size.

PDF case: It affects only the graphic, not the page format/size of the PDF file.

Best regards
Torquil Sørensen
Ben Abbott
2009-07-10 01:27:12 UTC
Permalink
Post by Torquil Macdonald Sørensen
Post by Ben Abbott
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The resulting PDF
looks like an A4 page, even though the actual plot is wider than its height
(standard format). I'm using octave 3.2 and the newest gnuplot development
snapshot. Plotting to PDF with gnuplot works fine using the
pdfcairo terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil Sørensen
It's not clear to me what you are seeing, or what you expect to
see. So I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and
paperposition properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a
8x6 in box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document (or
a figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf
Ben
Thanks Ben, I will try to explain more thoroughly and provide some
files. When using the plot command, a window appears, with certain
dimensions. This window is a bit wider than it is tall. I would like
the PDF to have the same dimensions.
When I use the print command to obtain an EPS file, the EPS has the
same aspect ratio as this window. When printing to PDF, there is
lots of extra white space above and below the plot. So the result is
not the same when printing to EPS and PDF. So printing to EPS gives
the desired result.
(Btw, I assume you meant "print test.pdf", not "plot plot.pdf" in
your example code above)
plot (1:10)
print plot.eps
Result: http://folk.uio.no/tmac/plot.eps
plot (1:10)
print plot.pdf
Result: http://folk.uio.no/tmac/plot.pdf
The EPS has the format that I want, and which is the same as the
plot window displayed by octave after the plot command.
EPS case: It affects the aspect ratio of the graphic, as well as the
paper format/size.
PDF case: It affects only the graphic, not the page format/size of the PDF file.
Best regards
Torquil Sørensen
Thanks for providing more detail.

The behavior of Octave is consistent with Matlab and is intended.

To obtain a pdf file that is the same size as the eps

dpi = get (0, "screenpixelsperinch");
pos = get (gcf, "position");
papersize = pos(3:4)./dpi;
set (gcf, "papersize", papersize)
set (gcf, "paperposition", [0, 0, papersize])
plot(1:10)
print test.pdf

If you compare the the eps file, be sure your viewer clips the result
at the bounding box. Otherwise, you'll see an additional 50pt border.

Ben
Francesco Potorti`
2009-07-10 06:31:21 UTC
Permalink
Post by Ben Abbott
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
Is this for compatibility with Matlab? If not, it would be nice to have
cm and A4 as the defaults.
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: ***@isti.cnr.it
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/
Ben Abbott
2009-07-10 08:12:54 UTC
Permalink
Post by Francesco Potorti`
Post by Ben Abbott
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
Is this for compatibility with Matlab? If not, it would be nice to have
cm and A4 as the defaults.
I'm no fan of inches either.

However, Matlab's default units for figure's paper properties are
"inches", for the position property are "pixels" for fonts are
"points" for the axes are "normalized" ... etc. For compatibility,
Octave's defaults units are the same.

When the property listeners for units conversion are in place the
defaults can be set to anything the user desires. Until then if the
units for these properties are changed, I resulting behavior will not
be was is expected.

Ben
Jonathan Stickel
2009-07-10 13:53:19 UTC
Permalink
Subject: Re: Plot to PDF
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The
resulting PDF
looks like an A4 page, even though the actual plot is wider than its
height
(standard format). I'm using octave 3.2 and the newest gnuplot
development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo
terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do
it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil S?rensen
It's not clear to me what you are seeing, or what you expect to see.
So I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a 8x6
in box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document (or a
figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf
Ben
This makes a nice looking plot, but it is in the lower left corner of an
8.5x11 in page! It seems that the papersize is not being respected.
Interestingly, the fonts of the pdf output are nice and large. However,
if I subsequently print to eps, the fonts are tiny in the eps output.

Jonathan
Ben Abbott
2009-07-10 16:04:43 UTC
Permalink
Post by Jonathan Stickel
Subject: Re: Plot to PDF
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The
resulting PDF
looks like an A4 page, even though the actual plot is wider than its
height
(standard format). I'm using octave 3.2 and the newest gnuplot
development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo
terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do
it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil S?rensen
It's not clear to me what you are seeing, or what you expect to see.
So I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a 8x6
in box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document (or a
figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf
Ben
This makes a nice looking plot, but it is in the lower left corner of an
8.5x11 in page! It seems that the papersize is not being respected.
Interestingly, the fonts of the pdf output are nice and large. However,
if I subsequently print to eps, the fonts are tiny in the eps output.
Jonathan
Thanks for catching the papersize bug. This is due to ghostscript. Presently ghostscript is used to produce a pdf from a postscript output. The postscript is the proper size (per the bounding box) but the resulting pdf is letter size (or perhaps a4). The solution will be to explicitly tell ghostscript the size of the page by using the options ...

-dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h

Where w and h are in points.

Another solution is to run the developers version of gnuplot (version >= 4.3).

Regarding the eps fontsize, this is a gnuplot feature. I don't have a gnuplot manual handy, but I recall the decreased fontsize is documented. Perhaps we should use ghostscript to convert from ps to eps so that we obtain consistent fontsizes?

I'll add these to my list of things that need work. However, my computer is still out for repair and I'm very busy with selling my home, packing, and moving ... it might be a few weeks before I can get to this. So if anyone has the initiative, please dig in.

Ben
Jonathan Stickel
2009-07-10 16:24:31 UTC
Permalink
On Friday, July 10, 2009, at 09:53AM, "Jonathan Stickel"
Post by Jonathan Stickel
text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out
wrong. The resulting PDF looks like an A4 page, even though
the actual plot is wider than its height (standard format).
I'm using octave 3.2 and the newest gnuplot development
snapshot. Plotting to PDF with gnuplot works fine using the
pdfcairo terminal.
fplot(blablabla...) print("plot.pdf")
It works, apart from that page format issue. Anyone know how
to do it right? I'm using the octave3.2 from Debian Sid.
Thanks Torquil S?rensen
It's not clear to me what you are seeing, or what you expect to
see. So I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and
paperposition properties.
The default are
papersize = [8.5, 11]; paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a
8x6 in box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document
(or a figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8]) set (gcf, "paperposition", [0,
0, 6.4, 4.8]) plot (1:10) xlabel ("xlabel") ylabel ("ylabel")
title ("title") plot test.pdf
Ben
This makes a nice looking plot, but it is in the lower left corner
of an 8.5x11 in page! It seems that the papersize is not being
respected. Interestingly, the fonts of the pdf output are nice and
large. However, if I subsequently print to eps, the fonts are tiny
in the eps output.
Jonathan
Thanks for catching the papersize bug. This is due to ghostscript.
Presently ghostscript is used to produce a pdf from a postscript
output. The postscript is the proper size (per the bounding box) but
the resulting pdf is letter size (or perhaps a4). The solution will
be to explicitly tell ghostscript the size of the page by using the
options ...
-dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h
Where w and h are in points.
Another solution is to run the developers version of gnuplot (version
Post by Jonathan Stickel
= 4.3).
Regarding the eps fontsize, this is a gnuplot feature. I don't have a
gnuplot manual handy, but I recall the decreased fontsize is
documented. Perhaps we should use ghostscript to convert from ps to
eps so that we obtain consistent fontsizes?
I'll add these to my list of things that need work. However, my
computer is still out for repair and I'm very busy with selling my
home, packing, and moving ... it might be a few weeks before I can
get to this. So if anyone has the initiative, please dig in.
Ben
OK. BTW, a big thanks for all your work on the plotting code.

Until this can be fixed within Octave, one workaround is to crop the pdf
file after creation. The perl script "pdfcrop" does a good job, and it
is included with texlive.

Jonathan
Dr. Ing. Dieter Jurzitza
2009-07-10 18:03:24 UTC
Permalink
Hi folks,
to whom it may concern: I do exactly this since quite some time. I have the
script "gnuplotps2pdf" what does what it is called - and even more.
I've attached it here - you can use it even for any (AFAIK) postscript output
from M$-Software in order to shrink the box down to it's absolute minimum.
Just call

gnuplotps2pdf <filename>

to create a minimum box size pdf from any postscript. If you have gv, you can
use that to determine a box within any postscript file to create a pdf the
size of which matches exactly the size of the selection.

It works under linux. You need extra effort on MAC (install gnu grep, edit
file ...), on M$ - no way.

I prefer it over pdfcrop as it may use the postscript output of anything
directly.

Take care



Dieter Jurzitza
On Friday, July 10, 2009, at 09:53AM, "Jonathan Stickel"
*****
--
-----------------------------------------------------------

|
\
/\_/\ |
| ~x~ |/-----\ /
\ /- \_/
^^__ _ / _ ____ /
<°°__ \- \_/ | |/ | |
|| || _| _| _| _|

if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------
Ben Abbott
2009-07-10 16:23:00 UTC
Permalink
Post by Ben Abbott
Post by Jonathan Stickel
Subject: Re: Plot to PDF
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes
Post by Torquil Macdonald Sørensen
Hi!
When I plot to pdf in octave, the page format turns out wrong. The
resulting PDF
looks like an A4 page, even though the actual plot is wider than its
height
(standard format). I'm using octave 3.2 and the newest gnuplot
development
snapshot. Plotting to PDF with gnuplot works fine using the pdfcairo
terminal.
fplot(blablabla...)
print("plot.pdf")
It works, apart from that page format issue. Anyone know how to do
it right? I'm
using the octave3.2 from Debian Sid.
Thanks
Torquil S?rensen
It's not clear to me what you are seeing, or what you expect to see.
So I'll explain what should happen and you can comment.
Both pdf an postscript output respect the papersize and paperposition
properties.
The default are
papersize = [8.5, 11];
paperposition = [0.25, 2.5, 8.0, 6.0];
The resulting pdf/postscript output should (approximately) fill a 8x6
in box centered on a page of 8.5x11 inches.
If this is what you see, then all is working correctly.
If you'd like to produce a pdf to import into a LaTeX document (or a
figure for a similar purpose), then try
set (gcf, "papersize", [6.4, 4.8])
set (gcf, "paperposition", [0, 0, 6.4, 4.8])
plot (1:10)
xlabel ("xlabel")
ylabel ("ylabel")
title ("title")
plot test.pdf
Ben
This makes a nice looking plot, but it is in the lower left corner of an
8.5x11 in page! It seems that the papersize is not being respected.
Interestingly, the fonts of the pdf output are nice and large. However,
if I subsequently print to eps, the fonts are tiny in the eps output.
Jonathan
Thanks for catching the papersize bug. This is due to ghostscript. Presently ghostscript is used to produce a pdf from a postscript output. The postscript is the proper size (per the bounding box) but the resulting pdf is letter size (or perhaps a4). The solution will be to explicitly tell ghostscript the size of the page by using the options ...
-dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h
Where w and h are in points.
Another solution is to run the developers version of gnuplot (version >= 4.3).
Regarding the eps fontsize, this is a gnuplot feature. I don't have a gnuplot manual handy, but I recall the decreased fontsize is documented. Perhaps we should use ghostscript to convert from ps to eps so that we obtain consistent fontsizes?
I downloaded the gnuplot 4.3 manual to refresh my memory. In the postscript terminal section, it states; "In *eps* mode the whole plot, including the fonts, is reduced to half of the default size."

Rather than relying on ghostscript, another solution would be scale the fontsizes of all text while producing the eps output and then return the fonts to their stated size when done.

Ben
Continue reading on narkive:
Loading...