0

I am trying to put table in the form of Grid into GraphicsGrid. Here is my code:

sinfunc[ampl_, freq_, phase_, x_] := ampl Sin[2. Pi freq x + phase];
A1 = 1.;
A2 = 0.5;
f1 = 2.;
f2 = 5.;
phase1 = Pi/4.;
phase2 = Pi/3.;
plotstyle = {Blue, Red};
padding = {{25, 5}, {15, 5}};

plot = Plot[{sinfunc[A1, f1, phase1, x], sinfunc[A2, f2, phase2, x]}, {x, 0., 2. Pi}, PlotRange -> {{0., 2. Pi}, {-1., 1.}}, AxesOrigin -> {0., -1.}, PlotStyle -> plotstyle, Frame -> True, ImagePadding -> padding]; emptyplot = Plot[{}, {x, 0., 2. Pi}, PlotRange -> {{0., 2. Pi}, {-1., 1.}}, AxesOrigin -> {0., -1.}, PlotStyle -> plotstyle, Frame -> True, FrameStyle -> Directive[White, Opacity[0.]], ImagePadding -> padding];

legendSin1 = LineLegend[{plotstyle[[1]]}, {""}, LabelStyle -> {0}, LegendMarkerSize -> {25, 5}]; legendSin2 = LineLegend[{plotstyle[[2]]}, {""}, LabelStyle -> {0}, LegendMarkerSize -> {25, 5}];

size = 12; text = Partition[ Style[#, size] & /@ {"", "Sin1", "Sin2", "", "", "", "Frequency", ToString[f1], ToString[f2], "Amplitude", ToString[A1], ToString[A2], "Phase", ToString[Round[phase1, 0.01]], ToString[Round[phase2, 0.01]]}, 3]; table = Grid[text, Dividers -> {All, {1 -> True, 3 -> True, 4 -> True, 5 -> True, 6 -> True}}, Alignment -> {Center, Center, {{3, 5}, {2, 3}} -> Left}, Spacings -> {1, 1.2} , Frame -> {None, None, {{3, 5}, {2, 3}} -> Directive[(Thickness[2])Thickness[0.005], Black]} ];

grid = GraphicsGrid[{{emptyplot, plot}}, Epilog -> {Inset[table, Scaled[{0.1, 0.5}]], Inset[legendSin1, Scaled[{0.15, 0.63}]], Inset[legendSin2, Scaled[{0.255, 0.63}]]}]

When I save the grid as PDF (Export["Grid.pdf", grid]). I get following image:

enter image description here

(Please notice that I am interested in PDF format of image, here I put JPG format due to format upload restrictions.)

I am facing two one problem:

  1. LineLegends legendSin1 and legendSin2 are missing in the PDF. However, they are present in the Mathematica notebook view of GraphicsGrid grid.
  2. The table (Grid) appears as black rectangle. This in fact might be somehow related to the option Frame. If the Frame is commented out, the table appears normally. @MelaGo solved this problem by changing the thickness of Frame to e.g. Thickness[0.005] instead of Thickness[2].

I am using 12.1 version of Mathematica. I will be grateful for any help.

Moonwalk
  • 641
  • 3
  • 8
  • The black box is due to Thickness[2] - lines are so wide they fill up the grid. Try Thickness[.02] – MelaGo Mar 23 '21 at 01:50
  • @MelaGo Thank you! It solved my second problem. I edited my question. – Moonwalk Mar 23 '21 at 08:50
  • Your code works fine in Mathematica 12.2 with windows 10 (LineLegends exist in pdf). – Ben Izd Mar 23 '21 at 12:17
  • @BenyIzd You are right. I asked my colleague to run it on Mathematica 12.2 and I can confirm that LineLegends exist in pdf. I am using the 12.1 and they are missing in pdf. I wonder if somebody else can confirm this on 12.1. – Moonwalk Mar 23 '21 at 13:55
  • Version 12.1 seems to have some problems exporting to pdf, there was another question similar issue with the same version. – Ben Izd Mar 23 '21 at 14:34

0 Answers0