I've got a graphic that I'd like to save as an eps file. Trouble is, the graphic has some transparency to it. Since the eps format doesn't handle transparency, I want to flatten the transparency out, effectively making an image with no transparency on a fixed (white) background that looks like the original transparent image.
To give some background: To make my original image, I started with a plot, combined it with some background grids, and rasterized the result with Background->None. I then combined the image with an image of (vector) grid axes. I do this because I need the plot rasterized because it's built from a very large data set, but I need the axes vectorized because I need them to appear in a LaTeX document. I set Background->None in order to keep the plot's white background from blotting out the axes, and I combined the original plot with background grids so that the grids can be seen behind the image when rasterized.
Currently when I try to save the document as an eps it gets rid of the transparency in the rasterized plot, which ends up meaning that the grids can no longer be seen through it. I'd like to be able to save as an eps and "flatten" the transparency, so that the image looks like it does with the transparency without the document actually using transparency (since eps can't handle transparency). Alternatively, if I could save it as a pdf but still get rid of the transparency in a similar way that would also be acceptable. I need to save the document in a vector format to keep the axes looking right.
In case anyone is curious, here is my code. RatioPlotData is a big (~2,000 points) array.
SetDirectory[NotebookDirectory[]];
SetOptions[$FrontEnd, PrintingStyleEnvironment -> "Working"];
in = 72;
G3D = Graphics3D[AlignmentPoint -> Center, AspectRatio -> 0.925,
Axes -> {True, True, True},
AxesEdge -> {{-1, -1}, {-1, -1}, {-1, 1}},
AxesStyle -> Directive[10, Black],
BaseStyle -> {FontFamily -> "Arial", FontSize -> 12},
Boxed -> False, BoxRatios -> {3, 3, 1},
LabelStyle -> Directive[Black], ImagePadding -> 40,
ImageSize -> 5 in, PlotRangePadding -> 0,
TicksStyle -> Directive[10], ViewPoint -> {-2, -2, 2},
ViewVertical -> {0, 0, 1}];
(*axesLabels=Graphics3D[{Text[Style["v",Black,12],Scaled[{.5,-.15,0}],\
{0,0},{1.,0}],Text[Style["u",Black,12],Scaled[{-.15,.5,0}],{0,0},{1.,\
0}],Text[Style["Subsuperscript[R, 6, (3)]/Subsuperscript[R, 6, \
(2)]",Black,12],Scaled[{-.2,1.15,.6}],{0,0},{1.0,0}],Text[Style[\
"Collinear \
Limit",ColorData[1,2],12],Scaled[{0.5,0.5,-0.2}],{0,0},{1.0,0}]}];*)
fig = Show[
ListPlot3D[
Join[Append[RatioPlotData, {1, 1, -7.004088513718098`}],
Join[Transpose[Prepend[Transpose[ratlinepoints], Table[1, {19}]]],
Transpose[{Transpose[ratlinepoints][[1]], Table[1, {19}],
Transpose[ratlinepoints][[2]]}]]],
PlotRange -> {{0, 1}, {0, 1}, {-7.35, -7}}, ClippingStyle -> None,
Mesh -> {{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, {0.1, 0.2,
0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}}, MeshStyle -> Gray,
PlotStyle -> Opacity[0.8](*,AxesLabel->{"v","u","R63/R62"}*)],
ImagePadding -> {{70, 10}, {15, 0}}, Options[G3D]]
(*collline=Show[ParametricPlot3D[{u,1-u,-7.35},{u,0,1},PlotStyle->{\
ColorData[1,2],Dashed,Thick}],AbsoluteOptions[fig]]*)
axes = Show[
Graphics3D[{},
FaceGrids -> {{{1, 0,
0}, {{0, 0.2, 0.4, 0.6, 0.8,
1}, {-7.0, -7.1, -7.2, -7.3, -7.35}}}, {{0, 1,
0}, {{0, 0.2, 0.4, 0.6, 0.8,
1}, {-7.0, -7.1, -7.2, -7.3, -7.35}}}, {{0,
0, -1}, {{0.2, 0.4, 0.6, 0.8}, {0.2, 0.4, 0.6, 0.8}}}},
AbsoluteOptions[fig]](*,axesLabels,collline*)];
fig = Show[fig,
FaceGrids -> {{{1, 0,
0}, {{0, 0.2, 0.4, 0.6, 0.8,
1}, {-7.0, -7.1, -7.2, -7.3, -7.35}}}, {{0, 1,
0}, {{0, 0.2, 0.4, 0.6, 0.8,
1}, {-7.0, -7.1, -7.2, -7.3, -7.35}}}, {{0,
0, -1}, {{0.2, 0.4, 0.6, 0.8}, {0.2, 0.4, 0.6, 0.8}}}}];
fig = Show[fig, AxesStyle -> Directive[Opacity[0]]];
Row[{fig, axes}]
fig = Magnify[fig, 5];
fig = Rasterize[fig, Background -> None];
axes = First@ImportString[ExportString[axes, "PDF"], "PDF"];
result = Show[axes,
Epilog -> Inset[fig, {0, 0}, {0, 0}, ImageDimensions[axes]],
Background -> White];
result
eps
which will invokeghostscript
to perform the flattening. Not sure if this works for your case - let me know if it does. $\endgroup$Overlay
instead ofShow
to render the vector graphic on top of theRasterize
d graphic. The disadvantage is that Overlay is actually 'low-level overlay', it really just stacks graphics on top of each other no matter what they show, so you would have to align the plot and axes manually (e.g. ensuring the same plot range). $\endgroup$Overlay
method is to look at the FullForm of theShow
result. Perhaps you can use the options from it to render your plots separately, perhaps you might even want to work with the Graphics primitives produced by Show ... try it out. I don't see a more direct solution to your question so far. $\endgroup$