Mathematica: Rasters in 3D graphics?

The complete solution for Mathematica 7.0.1: fixing bugs The code with comments: (*controls the resolution of rasterized graphics*) magnification = 5; SetOptions$FrontEnd, PrintingStyleEnvironment -> "Working" (*Turn off history for saving memory*) $ (*Epilog will give us the bounding box of the graphics*) g1 = Plot3DSinx y, {x, 0, Pi}, {y, 0, Pi}, AlignmentPoint -> Center, AspectRatio -> 0.925, Axes -> {True, True, True}, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False, BoxRatios -> {3, 3, 1}, LabelStyle -> DirectiveBlack, ImagePadding -> All, ImageSize -> 5*72, PlotRange -> All, PlotRangePadding -> None, TicksStyle -> Directive10, ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}, AxesStyle -> DirectiveOpacity0, FaceGrids -> {{-1, 0, 0}, {0, 1, 0}}, Mesh -> None, ImagePadding -> 40, Epilog -> {Red, AbsoluteThickness1, Line{ImageScaled{0, 0}, ImageScaled{0, 1}, ImageScaled{1, 1}, ImageScaled{1, 0}, ImageScaled{0, 0}}}; (*The options list should NOT contain ImagePadding->Full. Even it is \ before ImagePadding->40 it is not replaced by the latter-another bug! *) axes = Graphics3D{Opacity0, PointPlotRange /.

AbsoluteOptionsg1 // Transpose}, AlignmentPoint -> Center, AspectRatio -> 0.925, Axes -> {True, True, True}, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, AxesStyle -> Directive10, Black, BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False, BoxRatios -> {3, 3, 1}, LabelStyle -> DirectiveBlack, ImageSize -> 5*72, PlotRange -> All, PlotRangePadding -> None, TicksStyle -> Directive10, ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}, ImagePadding -> 40, Epilog -> {Red, AbsoluteThickness1, Line{ImageScaled{0, 0}, ImageScaled{0, 1}, ImageScaled{1, 1}, ImageScaled{1, 0}, ImageScaled{0, 0}}}; (*fixing bug with ImagePadding loosed when specifyed as option in \ Plot3D*) g1 = AppendTog1, ImagePadding -> 40; (*Increasing ImageSize without damage. Explicit setting for \ ImagePadding is important (due to a bug in behavior of \ ImagePadding->Full)! *) g1 = Magnifyg1, magnification; g2 = Rasterizeg1, Background -> None; (*Fixing bug with non-working option Background->None when graphics \ is Magnifyed*) g2 = g2 /.

{255, 255, 255, 255} -> {0, 0, 0, 0}; (*Fixing bug with icorrect exporting of Ticks in PDF when Graphics3D \ and 2D Raster are combined*) axes = First@ImportStringExportStringaxes, "PDF", "PDF"; (*Getting explicid ImageSize of graphics imported form PDF*) imageSize = Last@Transpose{First@#, Last@#} & /@ Sort /@ Transpose@ First@Casesaxes, Style{Linex_}, ___, RGBColor1. `, 0. `, 0.

`, 1. `, ___ :> x, Infinity (*combining Graphics3D and Graphics*) result = Showaxes, Epilog -> Insetg2, {0, 0}, {0, 0}, imageSize Export"C:\\result. Pdf", result Here is what I see in the Notebook: And here is what I get in the PDF.

In Win7/M8.01 I don't see the axes and tick labels when running the above code. – Sjoerd C. De Vries Jun 10 at 14:31 @Sjoerd @belisarius I think we can conclude that some graphics functionality is broken in v.8... ;) – Alexey Popkov Jun 10 at 15:32 @Alexey, thank you for trying a different approach.

I'll be checking on this once I install M8. – jmlopez Jun 10 at 18:17 @Alexey, I think the problem is that M8 does not export png or rasterized images with transparent background. For this reason, when you attempt to place g2 on top then you see no axes and tick labels (background of rasterized image is white).

– jmlopez Jun 10 at 23:46 @jmlopez Please see edited version of the answer. It seems that I got it (at least for Mathematica 7.0.1)! – Alexey Popkov 8.018 at 3:33.

Just checking (Mma8): SetOptions$FrontEnd, PrintingStyleEnvironment -> "Working"; in = 72; G3D = Graphics3DAlignmentPoint -> Center, AspectRatio -> 0.925, Axes -> {True, True, True}, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, AxesStyle -> Directive10, Black, BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False, BoxRatios -> {3, 3, 1}, LabelStyle -> DirectiveBlack, ImagePadding -> All, ImageSize -> 5 in, PlotRange -> All, PlotRangePadding -> None, TicksStyle -> Directive10, ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}; g = ShowPlot3DSinx y, {x, 0, Pi}, {y, 0, Pi}, Mesh -> None, AxesLabel -> {"x", "y", "z"}, OptionsG3D; axes = Graphics3D{}, AbsoluteOptionsg; fig = Showg, AxesStyle -> DirectiveOpacity0, FaceGrids -> {{-1, 0, 0}, {0, 1, 0}}; Export"c:\\Axes. Pdf", axes, Background -> None; Export"c:\\Fig. Pdf", Rasterizefig, ImageResolution -> 300; a = Import"c:\\Axes.

Pdf"; be = Import"c:\\Fig. Pdf"; Export"c:\\FinalFig. Pdf", Showb, a.

With Mathematica 7.0.1 with this code I get the same image as showed in the question. – Alexey Popkov Jun 10 at 14:29 @Alexey I think we can conclude that the Export to PDF feature was fixed in v8 ... – belisarius Jun 10 at 14:38 Works for me. Win7/M8.01 – Sjoerd C.De Vries Jun 10 at 14:52 So... all this time I've had problems because of Mathematica 7?

Dear lord! I've also been having lots of problem using Graphics. Maybe switching to M8 will solve the problems.

Anyway, thank you for checking. Now I'm wondering, which answer should I accept? Mathematica is simply broken.

– jmlopez Jun 10 at 17:05 @jmlopez You should accept the answer that you found to be the most helpful to you as per meta.stackoverflow. Com/questions/5234/… :) – belisarius Jun 10 at 17:09.

In Mathematica 8 the problem may be solved even simpler using new Overlay function. Here is the code from the UPDATE section of the question: SetOptions$FrontEnd, PrintingStyleEnvironment -> "Working"; $ in = 72; G3D = Graphics3DAlignmentPoint -> Center, AspectRatio -> 0.925, Axes -> {True, True, True}, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, AxesStyle -> Directive10, Black, BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False, BoxRatios -> {3, 3, 1}, LabelStyle -> DirectiveBlack, ImagePadding -> 40, ImageSize -> 5 in, PlotRange -> All, PlotRangePadding -> 0, TicksStyle -> Directive10, ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}; axesLabels = Graphics3D{TextStyle"x axis (units)", Black, 12, Scaled{.5, -.1, 0}, {0, 0}, {1, -.9}, TextStyle"y axis (units)", Black, 12, Scaled{1.1, .5, 0}, {0, 0}, {1, .9}, TextStyle"z axis (units)", Black, 12, Scaled{0, -.15, .7}, {0, 0}, {-.1, 1.5}}; fig = ShowPlot3DSinx y, {x, 0, Pi}, {y, 0, Pi}, Mesh -> None, ImagePadding -> {{40, 0}, {15, 0}}, OptionsG3D; axes = Show Graphics3D{}, FaceGrids -> {{-1, 0, 0}, {0, 1, 0}}, AbsoluteOptionsfig, axesLabels, Epilog -> TextStyle"Panel A", Bold, Black, 12, ImageScaled{0.075, 0.975}; fig = Showfig, AxesStyle -> DirectiveOpacity0; And here is the solution: gr = Overlay{axes, Rasterizefig, Background -> None, ImageResolution -> 300} Export"Result. Pdf", gr In this case we need not to convert fonts to outlines.

UPDATE As jmlopez pointed out in the comments to this answer, the option Background -> None does not work properly under Mac OS X in Mathematica 8.0.1. One workaround is to replace white non-transparent points by transparent: gr = Overlay{axes, Rasterizefig, Background -> None, ImageResolution -> 300 /. {255, 255, 255, 255} -> {0, 0, 0, 0}} Export"Result.

Pdf", gr.

Something is not working when I try it. I only get fig with a white background. Is as if Rasterized ignored the background option.

– jmlopez Oct 10 at 17:01 @jmlopez Are you using Mathematica 8.0.1? I use Windows version. The output looks good both inside of the Notebook and in PDF viewer.

But exporting to EPS in this case works not so well. – Alexey Popkov Oct 10 at 18:19 I'm using MMA 8.0.1 in Mac OS X. I think there is a problem with Graphics3D or Rasterize.

Take for instance: Overlay{fig, Plotx, {x, 1, 2}} with fig as defined in your post. Then overlay works. But if you try: Overlay{fig, Graphics3D} then it doesn't show fig.It might be a bug on the mac version.

– jmlopez Oct 10 at 18:27 @jmlopez Try Overlay{fig, RasterizeGraphics3D, Background -> None}. This works on my system. With the original code from my answer you could try also Rasterizefig,Background->None,ImageResolution->300/.

{Repeated255,{4}}->{0,0,0,0}. – Alexey Popkov Oct 10 at 18:40 That works. Unfortunately that seems to take longer to compute than in the previous method.

Well, hopefully by the next release it will be fixed on the mac. – jmlopez Oct 10 at 19:57.

Here I present another version of the original solution which uses the second argument of Raster instead of Inset. I think that this way is a little more straightforward. Here is the code from the UPDATE section of the question (modified a bit): SetOptions$FrontEnd, PrintingStyleEnvironment -> "Working"; $ in = 72; G3D = Graphics3DAlignmentPoint -> Center, AspectRatio -> 0.925, Axes -> {True, True, True}, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, AxesStyle -> Directive10, Black, BaseStyle -> {FontFamily -> "Arial", FontSize -> 12}, Boxed -> False, BoxRatios -> {3, 3, 1}, LabelStyle -> DirectiveBlack, ImagePadding -> 40, ImageSize -> 5 in, PlotRange -> All, PlotRangePadding -> 0, TicksStyle -> Directive10, ViewPoint -> {2, -2, 2}, ViewVertical -> {0, 0, 1}; axesLabels = Graphics3D{TextStyle"x axis (units)", Black, 12, Scaled{.5, -.1, 0}, {0, 0}, {1, -.9}, TextStyle"y axis (units)", Black, 12, Scaled{1.1, .5, 0}, {0, 0}, {1, .9}, TextStyle"z axis (units)", Black, 12, Scaled{0, -.15, .7}, {0, 0}, {-.1, 1.5}}; fig = ShowPlot3DSinx y, {x, 0, Pi}, {y, 0, Pi}, Mesh -> None, ImagePadding -> {{40, 0}, {15, 0}}, OptionsG3D; axes = Show Graphics3D{}, FaceGrids -> {{-1, 0, 0}, {0, 1, 0}}, AbsoluteOptionsfig, axesLabels, Prolog -> TextStyle"Panel A", Bold, Black, 12, ImageScaled{0.075, 0.975}; fig = Showfig, AxesStyle -> DirectiveOpacity0; fig = Magnifyfig, 5; fig = Rasterizefig, Background -> None; axes2D = First@ImportStringExportStringaxes, "PDF", "PDF"; The rest of the answer is the new solution.At first, we set the second argument of Raster so that it will fill the complete PlotRange of axes2D.

The general way to do this is: fig = fig /. Rasterdata_, rectangle_, opts___ :> Rasterdata, {Scaled{0, 0}, Scaled{1, 1}}, opts; Another way is to make direct assignment to the corresponding Part of the original expression: fig1, 2 = {Scaled{0, 0}, Scaled{1, 1}} Note that this last code is based on the knowledge of internal structure of the expression generated by Rasterize which is potentially version-dependent. Now we combine two graphical objects in a very straightforward way: result = Showaxes2D, fig And export the result: Export"C:/Result.

Pdf", result; Export"C:/Result. Eps", result; Both . Eps and .

Pdf are exported perfectly with Mathematica 8.0.4 under Windows XP 32 bit and look identical to the files exported with the original code: result = Showaxes2D, Epilog -> Insetfig, Center, Center, ImageScaled{1, 1} Export"C:/Result. Pdf", result; Export"C:/Result. Eps", result; Note that we need not necessarily to convert axes to outlines at least when exporting to PDF.

The code result = Showaxes, Epilog -> Insetfig, Center, Center, ImageScaled{1, 1} Export"C:/Result. Pdf", result; and the code fig1, 2 = {ImageScaled{0, 0}, ImageScaled{1, 1}}; result = Showaxes, Epilog -> First@fig Export"C:/Result. Pdf", result; produce PDF files looking identical to both previous versions.

This looks like much ado about nothing. As I read it, the problem you want to solve is the following: You want to export in a vector format, so that when printed the optimal resolution is used for fonts, lines and graphics In your edit program you don't want be bothered by the slowness of rendering a complex vector drawing These requirements can be met by exporting as . Eps and using an embedded rasterized preview image.

Export"file. Eps","PreviewFormat"->"TIFF" This will work in many applications. Unfortunately, MS Word's eps filter has been changing wildly over the last four versions or so, and whereas it once worked for me in one of the older functions it doesn't anymore in W2010.

I've heard rumors that it might work in the mac version, but I can't check right now.

I think that the idea of the question is really interesting from the practical point of view. I thought of this earlier but I found it too difficult or impossible. We have too many problems with PDF export of Graphics3D (and even Graphics!) in Mathematica. Any workarounds are interesting and possibly helpful for others.

– Alexey Popkov Jun 10 at 15:42 @Alexey I'm glad you find my question interesting. @Sjoerd could you write some code explaing how to export as eps and using embedded rasterized preview image? That would also be helpful to other users.

– jmlopez Jun 10 at 18:19 @jmlopez I added the requested line of code for those unable or unwilling to find it in the doc center. – Sjoerd C.De Vries Jun 11 at 14:33 Unless I'm not using it correctly all I obtain is a file with size bigger than without using that option. Try this in M7.0.1 Export"FIG.

Eps", Graphics3DSphere{0, 0, 0}, 1, Axes -> True, Background -> None, "PreviewFormat" -> "TIFF" with and without the option. "optimal resolution is used for fonts, lines and graphics". More specifically, fonts and simple lines in vector graphics, complex figures such as surfaces in rasterized versions.

This should reduce file size and give you some good looking plots. – jmlopez Jun 11 at 14:57 @jmlopez A bigger file size is to be expected. An eps with embedded preview contains both the vector description and a preview of how these should look like when rendered.

The idea is that your text editor should show the preview as a quick placeholder and should send the postscript stuff to the printer. – Sjoerd C. De Vries Jun 12 at 9:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions