2
$\begingroup$

I would like to save a list of plots generated using Table. I've tried to generate a 3 x 3 array of plots using the code shown bellow.

(But a general code can generate a n x n plot.)

My intent is to save the array of plots as a PDF file. However, although the code below works, it generates a messy PDF.

How can I solve this problem?

L = 15; pp = 100; k = 1;
f[x_, y_] = BesselJ[l, k  Sqrt[x^2 + y^2]];

outplot = 
  Table[
    DensityPlot[Abs[f[x, y]], {x, -L, L}, {y, -L, L}, 
      PlotRange -> Full,
      PlotPoints -> pp, 
      ColorFunction -> "Rainbow", 
      Axes -> True, 
      AxesLabel -> {x, y}, 
      LabelStyle -> Directive[Black, 12], 
      PerformanceGoal -> "Quality", 
      FrameTicks -> True, 
      Exclusions -> None], 
    {l, 0, 8}] 

Export["fxy.pdf", outplot, ImageResolution -> 300]
$\endgroup$
  • 2
    $\begingroup$ does Export["fxygrid.pdf", Grid@Partition[outplot, 3], ImageResolution -> 300] give what you need? $\endgroup$ – kglr Oct 3 at 16:28
2
$\begingroup$

The idea expressed in kglr's comment is a good one. I recommend you follow that advice and also make some changes to your plot generating code to

  1. Remove some unneeded options from DensityPlot.
  2. Add a label to each plot so it can be distinguished in the final array.
  3. Make changes to the code that will improve it robustness.

My recommended revisions to your code look like this:

Clear[f]
f[l_, k_][x_, y_] := BesselJ[l, k Sqrt[x^2 + y^2]]

With[{L = 15, pp = 100, k = 1},
  outplot =
    Grid[
      Partition[
        Table[
          DensityPlot[Abs[f[l, k][x, y]], {x, -L, L}, {y, -L, L},
            PlotPoints -> pp,
            ColorFunction -> "Rainbow",
            Axes -> True,
            AxesLabel -> {x, y},
            PlotLabel ->
            Row[{Style["l = ", FontFamily -> "Adobe Garamond Pro", Italic], l}],
            LabelStyle -> Directive[Black, 12]],
          {l, 0, 8}],
        3]]]

The grid of plots produced looks like this:

grid

Note: I specified

Row[{Style["l = ", FontFamily -> "Adobe Garamond Pro", Italic], l}]

to get a decent looking lower case letter "l" in the plot labels, one that can't easily be mistaken for a capital letter "i". However, the Adobe Garamond Pro font might not be installed on your system, so might change the specification to

Row[{"l = ", l}]

and accept the default font Mathematic uses.

Now the plot grid has been generated, it can exported like so:

Export[
  FileNameJoin[{$HomeDirectory, "Desktop", "fxy.pdf"}],
  outplot,
  ImageResolution -> 300]
$\endgroup$
  • $\begingroup$ Concerning fonts Row[{"l = ",l}] can be changed to Row[{Style[HoldForm@l, Italic, "InputForm"], "=", l}]. This gives "curved" l. $\endgroup$ – Alx Oct 4 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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