Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Export a graphical plot to pdf file

84 views
Skip to first unread message

Szymon Roziewski

unread,
Nov 7, 2012, 12:57:52 AM11/7/12
to

Hi there,

I have a ContourPlot result which I need to put into pdf file.
The problem is that the filled area is in a mess, I mean there are lots of
thin white stripes on it.

For example, please try out this bunch of code

gr = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
Export["file.pdf", gr]


Best regards,
Szymon Roziewski


Szymon Roziewski

unread,
Nov 7, 2012, 12:58:02 AM11/7/12
to

Hello,

I've found such a suggestion

antialias[g_] :=
ImageResize[
Rasterize[g, "Image", ImageResolution -> 600, Background -> White],
Scaled[2]]
g = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
img = antialias[Show[g, Axes -> False, Boxed -> False]];
Export["file.pdf", img, "AllowRasterization" -> False]

But the background is lightred although I set it up to be white.

Bes wishes,
Szymon Roziewski
--
Z wyrazami szacunku,
Szymon Roziewski


Nasser M. Abbasi

unread,
Nov 8, 2012, 7:03:26 PM11/8/12
to
Do not know much about this, but trying few things, I found this
to produce good image in the PDF file (no white stripes on it)

---------------------------
gr = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}]
Export["file.pdf", Rasterize[gr, ImageResolution -> 128]]
--------------------------------

You can change the options to Rasterize to see which gives
you best image in the PDF.

To obtain more information on the pdf file generated by
the export, you can list the Elements. something like:

---------------------------
lis = Import["file.pdf", "Elements"]
Grid[
Table[{lis[[i]], Import["file.pdf", lis[[i]]]}, {i, 1, Length[lis]}],
Frame -> All]
------------------------------

Another thing to try is to issue the command

SetOptions[$FrontEndSession, PrintingStyleEnvironment -> "Working"]

first before exporting. Again, this is something to try.
But the Rasterize'd image in PDF do not have the white stripes
any more.

--Nasser





Kevin J. McCann

unread,
Nov 10, 2012, 2:09:41 AM11/10/12
to
I have not done this; however, I frequently print out entire notebooks
as PDF's, and they appear fine. You could do that and then cut and paste
the PDF version of the plot. Just a suggestion.

Kevin

RBaillie

unread,
Nov 10, 2012, 2:09:51 AM11/10/12
to
Unfortunately, exporting to pdf has not worked properly since version
5.2. This export works fine in 5.2.

gr = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
Export["file.pdf", gr]

Moreover, the file created with version 5.2 is far smaller than with
later versions.

Often, using the
"AllowRasterization" -> False
option greatly improves exports to pdf with version 8, but it does not
work in this case.



Kristjan Kannike

unread,
Nov 10, 2012, 3:30:47 AM11/10/12
to
Hello,

The problem is that ContourPlot, DensityPlot etc. compose their plot of
lots of tiny polygons. PDF is a vector format and preserves them all. The
PDF file becomes large and loads and scrolls slowly.

There is a FixPolygons package that merges polygons of the same colour
that results in drastically reduced PDF size:

https://github.com/wspr/mmapkg

This works well with ContourPlot. Unfortunately not so well (sometimes)
with DensityPlot as its polygons are filled with gradients, not one
colour.

Best,
Kristjan Kannike

On Thu, 8 Nov 2012, Nasser M. Abbasi wrote:

> On 11/6/2012 11:57 PM, Szymon Roziewski wrote:

Szymon Roziewski

unread,
Nov 13, 2012, 12:15:00 AM11/13/12
to
Thank you all for your help.

This solution works almost well

antialias[g_] :=
ImageResize[
Rasterize[g, "Image", ImageResolution -> 600, Background -> White],
Scaled[2]]

g = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
img = antialias[Show[g, Axes -> False, Boxed -> False]];
Export["file.pdf", img, "AllowRasterization" -> False]

I mean the problem is with its background that is light red but it should
be white.

Best wishes,
Szymon Roziewski

On 12 November 2012 12:06, Szymon Roziewski <szymon.r...@gmail.com>wrote:

> Thank you all for your help.
>
> This solution works almost well
>
> antialias[g_] :=
> ImageResize[
> Rasterize[g, "Image", ImageResolution -> 600, Background -> White],
> Scaled[2]]
>
> g = ContourPlot[x^2 + y^2, {x, -1, 1}, {y, -1, 1}];
> img = antialias[Show[g, Axes -> False, Boxed -> False]];
> Export["file.pdf", img, "AllowRasterization" -> False]
>
> I mean the problem is with its background that is light red but it should
> be white.
>
> Best wishes,
0 new messages