1
$\begingroup$

This question already has an answer here:

I'm trying to plot several plots and graphics into Grid, but I have no success with proper alignment. Here is my code:

(*just allocating auxiliary variables*)
ClearAll;
SetDirectory[NotebookDirectory[]];
data = Import["MISFIT-GOF.DAT", "Table"];
parameters = 
Unevaluated /@ {fmin, fmax, NFREQ, MT, dt, nc, MaxV, EM1, PM1, EM2, 
PM2, EM3, PM3, EG1, PG1, EG2, PG2, EG3, PG3, TFEM, TFPM, FEM, FPM,
 TEM, TPM, TFRS1, TFRS2};
MapThread[Set, {parameters, Flatten[data]}];
df = (fmax - fmin)/(NFREQ - 1);(*frequency sampling*)
tstart = 0.;
tend = dt (MT - 1);
time = Table[i, {i, tstart, tend, dt}];
frequency = Table[i, {i, fmin, fmax, df}];

(*plotting*)
(*ArrayPlot of data of size (NFREQ = 569,MT = 3000) with AspectRatio->1*)
TFEM = Flatten[Import["TFEM1.DAT", "Table"]];
plotTFEM = 
ArrayPlot[Reverse[Partition[TFEM, MT]], AspectRatio -> 1, 
ColorFunction -> "TemperatureMap", PlotLegends -> Automatic];

(*plot below ArrayPlot*)
TEM = Flatten[Import["TEM1.DAT", "Table"]];
maxTEM = Max[Abs[TEM]];(*max. value*)
TEM = Partition[Riffle[time, TEM], 2];
plotTEM = 
ListLinePlot[TEM, PlotRange -> {{tstart, tend}, {-maxTEM, maxTEM}}, 
Frame -> True, 
FrameLabel -> {{None, 
Style["TEM", Black, 14]}, {Style["TIME[s]", Black, 14], None}}, 
FrameTicks -> {{None, All}, {All, None}}, 
FrameTicksStyle -> Directive[Black, 12], 
AxesOrigin -> {tstart, -maxTEM}];

(*plot on left side from ArrayPlot*)
FEM = Flatten[Import["FEM1.DAT", "Table"]];
maxFEM = Max[Abs[FEM]];(*max. value*)
FEM = Partition[Riffle[frequency, FEM], 2];
FEM[[All, {1, 2}]] = FEM[[All, {2, 1}]];(*change of axis*)
plotFEM = 
ListLinePlot[FEM, PlotRange -> {{-maxFEM, maxFEM}, {fmin, fmax}}, 
Frame -> True, 
FrameLabel -> {{Style["Frequency[Hz]", Black, 14], None}, {None, 
Style["FEM", Black, 14]}}, 
FrameTicks -> {{Automatic, None}, {None, All}}, 
FrameTicksStyle -> Directive[Black, 12], 
AxesOrigin -> {maxFEM, fmin}, AspectRatio -> GoldenRatio];

(*plot below TEM plot*)
S1 = Transpose[
Delete[Transpose[Import["S1.DAT", "Table"]], {{3}, {4}}]];
maxS1 = Max[Abs[S1[[All, 2]]]];
S1[[All, 2]] /= maxS1;(*normalization*)
S2 = Transpose[
Delete[Transpose[Import["S2.DAT", "Table"]], {{3}, {4}}]];
maxS2 = Max[Abs[S2[[All, 2]]]];
S2[[All, 2]] /= maxS2;(*normalization*)
plotS = ListLinePlot[{S1, S2}, PlotRange -> {{tstart, tend}, {-1, 1}},
PlotLegends -> Placed[LineLegend[{"S1", "S2"}], {0.85, 0.85}], 
Frame -> True, 
FrameLabel -> {{None, 
Style["Amplitude[m]", Black, 14]}, {Style["Time[s]", Black, 14],
None}},
FrameTicks -> {{None, All}, {All, None}}, 
FrameTicksStyle -> Directive[Black, 12]];

(*finally creating a grid of plots*)
With[{size = 300},
Grid[{{Show[plotFEM, ImageSize -> {Automatic, size}, 
ImagePadding -> {{40, 5}, {Automatic, 40}}],
Show[plotTFEM, ImageSize -> {Automatic, size}, 
ImagePadding -> {{Automatic, 43}, {Automatic, 40}}]},
{Show[Graphics[{Black, Circle[]}], ImageSize -> {100, 100}, 
ImagePadding -> {{5, Automatic}, {5, 5}}],
Show[plotTEM, ImageSize -> {size, Automatic}, 
ImagePadding -> {{0, 50}, {Automatic, 5}}]},
{Show[Graphics[{White, Circle[]}], ImageSize -> {100, 100}, 
ImagePadding -> {{5, Automatic}, {5, 5}}], 
Show[plotS, ImageSize -> {size, Automatic}, 
ImagePadding -> {{0, 50}, {Automatic, 5}}]}
}, Spacings -> {0, 0}]]

This is the output: enter image description here

I would like to get something like this(in terms of spacing and alignment): enter image description here

The last row of Grid contains white circle that's because in the last row I only want to have plotS. PlotS can have a same size as plotTEM or can be stretched across whole row. Please note that size and other parameters are not fixed and can be modified as one wish. The input files can be found here. Any help, suggestion or improvement of the code are more than welcomed. Thank you in advance!

$\endgroup$

marked as duplicate by MarcoB, user9660, Community May 22 '16 at 13:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Use Inset for more detailed positioning e.g. example. $\endgroup$ – Chris Degnen May 16 '16 at 12:12
  • $\begingroup$ If you think you will do this a lot, consider also the free SciDraw package: it was developed exactly for these purposes, I.e. to facilitate the production of "formatted" plots and sets thereof. $\endgroup$ – MarcoB May 16 '16 at 13:41
  • $\begingroup$ Thanks for your suggestions. @MarcoB, SciDraw pretty much solved my problem. Thanks aqain. $\endgroup$ – Moonwalk May 18 '16 at 7:49
  • $\begingroup$ @Moonwalk I'm glad it helped! $\endgroup$ – MarcoB May 18 '16 at 12:17
  • 2
    $\begingroup$ I'll suggest this question as possibly related: How can I make an X-Y scatter plot with histograms next to the X-Y axes?. Although it's not exactly the same problem, many of the techniques shown there would apply here as well. $\endgroup$ – MarcoB May 18 '16 at 12:22