Re: Questions concerning export of 3d plots

*To*: mathgroup at smc.vnet.net*Subject*: [mg118405] Re: Questions concerning export of 3d plots*From*: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>*Date*: Wed, 27 Apr 2011 05:37:25 -0400 (EDT)

Hi, I could write something like "What about Export["simple.pdf", Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}], "AllowRasterization" -> False] ? Cheers Patrick" but I don't, since I think this issue is not pointed out in the documentation well enough. Until now no one else answered which suggests that either no one else has these problems or nobody has a satisfying solution. I'm of the second kind and to be honest, I have a few other unsolved issues with the export of 3d graphics. Concerning your first question: I never had this specific issue but did you check to give some additional padding to your graphics, for instance with ImagePadding? What follows now is more or less personal observation and some hints. Everything was only tested on my Ubuntu 64bit [1]. There may be differences between the systems. Lets start from a simple example: Export["simple.pdf", Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}]] This creates here: - a file which is over 7MB in size - a pdf which takes about a minute to render in Adobe acroread - a plot where the mesh-lines look awful What happened? First thing to notice is that Mathematica does not rasterize the plot (completely) but stores some kind of polygons and lines directives in the pdf. For this it needs to project the 3d graphics directives in the same way like they are projected onto the 2d display for viewing. If there are polygons which are not visible, since they are covered by other polygons lying closer to the "viewer", they are *not* removed! The front polygons are simply drawn over them. In this exsample I would say 1/5 of the polygons are not visible and just increase file size. Simply removing them sounds great at first but imagine what happens if the surface is transparent. If pdf, svg or whatever vector-format you are using supports transparency you maybe need the underlying polygons. About the destroyed mesh-lines: When I remember right, then in former (aka in the good old) times the mesh was simply the sampling grid and therefore, was an intrinsic part of the surface (whether or not you draw it). Now the mesh is added separately which means it has its own Lines[..] which don't necessarily go along with the borders of the drawn polygons. Therefore, it can happen that a mesh-Line[..] goes a bit through a polygon and parts of this line are covered. This is in my opinion the reason why mesh-lines look a bit "disturbed". When you look at the created pdf a bit closer (and theres enough time while Adobe tries to display it) you see that the color of the surface seems smoother compared to the polygons that are drawn. In Mathematica (and OpenGL, ...) you say something like Polygon[{p1,p2,...}, VertexColors->{c1,c2,...}] and specify the color at each vertex. The whole polygon is then drawn by interpolating the colors of the vertices at each position. It "seems" (and here I'm really not sure) that either the PDF file format does not support this or it needs the hell of space for this. Maybe Mathematica rasterizes every little smoothly colored polygon and includes it as image in the pdf.. who knows. Lets look at this (no mesh, it looks awful anyway): Export["simple.pdf", Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Mesh -> None], "AllowRasterization" -> False] This pdf has a file-size of only 240kB and there are two obvious differences: - you have flat polygons which have only one single color. - it seems that there is a visible space between the polygons The second issue drew my attention. These spaces (I see them in every viewer) are not there but they are artefacts of the renderer of the pdf-viewer. To investigate this issue I switched to "SVG" export where you see the same behavior. I won't go into the exact reasons but this display error has its origin in the way how blending/masking is done at the borders of polygons. If you look into the SVG which is created by Mathematica you see that the edges of the polygons are not drawn (stroke==none). You can fix the svg file and give all polygons a stroke of say 0.5px with the same color as the polygon itself. So if you have for instance Inkscape installed to convert from svg to pdf, then you could compare these 3 pdf files: ExportSVG[filename_String, gr : (Graphics3D[___] | Graphics[___])] :== Block[{svg == ExportString[Normal[gr], "SVG"], stream}, Export[filename, StringReplace[svg, Shortest[ StringExpression["<polygon stroke==\"none\" fill==", color__, " points==", pt__, "/>"]] :> "<polygon stroke==" ~~ color ~~ " stroke-width==\"0.6px\" fill==" ~~ color ~~ " points==" ~~ pt ~~ "/>"], "Text"] ] gr == Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, Mesh -> None, MaxRecursion -> 5, PlotPoints -> 20, BoundaryStyle -> None, ImageSize -> 500]; Export["grMma1.pdf", gr] Export["grMma2.pdf", gr, "AllowRasterization" -> False] ExportSVG["grInk.svg", gr] Run["inkscape", "-D", "-A grInk.pdf", "grInk.svg"] On my machine I have sizes: 17M grMma1.pdf 860K grMma2.pdf 1.1M grInk.pdf and the last pdf looks pretty ok. I'm open for corrections, discussions or further information. Cheers Patrick [1] 8x Intel Core i7 2.8GHz, 12GB Ram, NVidia GTX 480 On Tue, 2011-04-19 at 06:57 -0400, Dominic W=C3=B6rner wrote: > Hi, > > I tried to export List3d plots with "save as" to insert them in a latex= > pdf document and got the following problems. > > 1. The axes labels are often cut > 2. The file size is of the order of a few MB which is too much. One way= > out of this would be to use bitmap renderization but then it looks > aweful. > > Cheers, > Dominic== >

**Re: Limit[f[x], x->a] vs. f[a]. When are they equal?**

**Re: Drawing a vector list**

**Questions concerning export of 3d plots**

**Re: Questions concerning export of 3d plots**