3
$\begingroup$

The following example data is from here.

The problem: To get the image inset into a Graphic object just large enough to hold the inset image.

The Inset technique was suggested here.

The context is that Labels are often exported rasterized and of poor quality. This is especially true in the case of 3D graphics.

The solution to these is to Graphics[Inset[yourimg]] when you export to PDF or SVG, which gives all labels etc. as vectorized.

Particularly powerful when you use MaTeX to produce publication quality graphics

meandatf1 = {1.48908, 1.49641, 1.49354, 1.50385, 1.49835, 1.49617, 
1.50569, 1.50117, 1.50226, 1.50151, 1.50108, 1.50031, 1.49955, 
1.49721, 1.49898, 1.50266, 1.50177, 1.50227, 1.49886, 1.50002}

meandatf2 = {-0.00127783, 0.000556012, 
0.0000143709, -0.000602328, -0.000375952, -0.00125357, 0.0000228143,
0.000175103, 0.000868018, -0.0003298, 0.000230178, 
0.000222689, -0.0000624273, -0.0000760139, -0.000263302, 
0.0000826082, 0.000206463, 0.0000507921, -0.0000955452, 
0.000184107}
genPlot[c_, dat_, ymin_, ymax_, legend_] := 
ListPlot[{Table[c, {Length[dat]}], dat}, AxesLabel -> {"N", "\[Mu]"},
PlotRange -> {Automatic, {ymin, ymax}}, 
PlotLegends -> Placed[legend, Above], Joined -> True, Mesh -> None, 
InterpolationOrder -> 0, 
 ImageSize -> 400] (*I tried also without ImageSize,see below*)

plot1 = genPlot[3/2, meandatf1, 1.45, 1.55, "\[ScriptCapitalD]1"];
plot2 = genPlot[0, meandatf2, -0.004, 0.004, "\[ScriptCapitalD]2"];

gg = Grid[{{plot1, plot2}}];
Graphics[Inset[gg, Automatic, Automatic,Scaled[1]], ImageSize -> {800, 400}]

Appreciate hints and tips.

$\endgroup$
2
  • $\begingroup$ maybe adding the options ImageSize -> {Full, Automatic}, (or ImageSize -> {800, Automatic}) and AspectRatio -> 1/3? $\endgroup$
    – kglr
    Commented Jan 1, 2018 at 3:21
  • $\begingroup$ Hmm, thanks. It looks like playing with AspectRatio alone is enough, and simplifies the export method to:Graphics[Inset[gg], AspectRatio -> 1/3] $\endgroup$
    – Hedgehog
    Commented Jan 1, 2018 at 3:31

1 Answer 1

1
$\begingroup$

Hat-tip to @kglr's comment:

I believe this is both the minimal solution and provides the best output: Note: there are subtleties when exporting that do not show in the notebook output, hence the need for the size arguments.

ggrough = Grid[{{plot1, plot2}}]
Export[NotebookDirectory[] <> "rough.pdf", ggrough]
Export[NotebookDirectory[] <> "rough.svg", ggrough]

ggsmooth = Graphics[Inset[gg], ImageSize -> {UpTo[900], UpTo[1100]}, AspectRatio -> 1/3]
Export[NotebookDirectory[] <> "smooth.pdf", ggsmooth]
Export[NotebookDirectory[] <> "smooth.svg", ggsmooth]

Rough notebook cell Smooth notebook cel

Check the SVG and PDF contents produced by the Export code above and you'll see the subtle differences.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.