10
$\begingroup$

Background

I am trying to create a three-graphics plot using the command GraphicsGrid[] to show the decomposition of the phase plane portrait; unfortunately, the plot created is very ugly since the axes of each graph are not aligned with each other; besides, the corresponding step size of the axes are not identical.

Sources

The differential equation of the dynamic system is given below:

f1 = {y''[t] ==  -9.82 Sin[y[t]] + 1.5 (y[t] - y'[t]), y[0] == 1, y'[0] == 0};

ss[t_] = NDSolve[f1, y, {t, 0, 10}]

Questions

  1. How to create a multi-graphics plot with axes aligned well automatically?
  2. How to make sure the step sizes of the axes are consistent with the corresponding axes of different graphics?

enter image description here

Updates

I have tried the solution (specifing the PlotRange and ImageSize of the graphic) offered by @Sumit, which works well in certain situation; however, the questions aforementioned still remain, shown as following: enter image description here

the associated codes are given as:

(*differenital equation:*)
f1 = {y''[t] ==  -9.82 Sin[y[t]] + 1.5 (y[t] - y'[t]), y[0] == 1,  y'[0] == 0};
ss[t_] = NDSolve[f1, y, {t, 0, 10}];
(*Graph 1: yy*)
yyt = Plot[y[t] /. ss[t], {t, 0, 10}, 
   PlotRange -> {{0, 10}, {-0.5, 1.5}}, ImageSize -> {360, 226}, 
   AxesLabel -> {"t", "\[Theta]"}];
yy = Rotate[yyt, -0.5 \[Pi]];
(*Graph 2: Dy*)
Dy = Plot[y'[t] /. ss[t], {t, 0, 10}, 
    PlotRange -> {{0, 10}, {-2, 1}},
    ImageSize -> {360, 245},  
    AxesLabel -> {"t", "\!\(\*FractionBox[\(d\[Theta]\), \(dt\)]\)"}];
(*Graph 3: yyDy--the phase plane portrait*)
yyDy = ParametricPlot[{y[t], y'[t]} /. ss[t], {t, 0, 10}, 
   PlotRange -> {{-0.5, 1.5}, {-2, 1}}, ImageSize -> {226, 245}, 
   AxesLabel -> {"\[Theta]", 
     "\!\(\*FractionBox[\(d\[Theta]\), \(dt\)]\)"}];
(*Create the multi-graphics plot*)
Grid[{{yyDy, Dy}, {yy}}]
$\endgroup$
1

2 Answers 2

11
$\begingroup$

Using same PlotRange would be a good start. For example

x[t_] = t Sin[t];
y[t_] = t Cos[t];
plot1 = ParametricPlot[{x[t], y[t]}, {t, 0, 2 Pi}, PlotRange -> {{-6, 6}, {-6, 6}},
        AxesLabel -> {"x", "y"}];
plot2 = ParametricPlot[{t, x[t]}, {t, 0, 2 Pi}, PlotRange -> {{-6, 6}, {-6, 6}},
        AxesLabel -> {"t", "x"}];
plot3 = ParametricPlot[{y[t], t}, {t, 0, 2 Pi}, PlotRange -> {{-6, 6}, {-6, 6}}, 
        AxesLabel -> {"y", "t"}];

Grid[{{plot3,}, {plot1, plot2}}]

enter image description here

You can do further adjustment by ImageSize, ImageMargins, FrameMargins etc.

Manual Adjust

Let's start from

f1 = {y''[t] == -9.82 Sin[y[t]] + 1.5 (y[t] - y'[t]), y[0] == 1, y'[0] == 0};
ss[t_] = y[t] /. NDSolve[f1, y, {t, 0, 10}][[1]];

pl1 = ParametricPlot[{ss[t], ss'[t]}, {t, 0, 2 Pi}, PlotRange -> {{-0.4, 0.4}, {-2, 1}}, 
      AspectRatio -> 1, ImageSize -> 200, AxesLabel -> {"x", "y"}];
pl2 = ParametricPlot[{ss[t], t}, {t, 0, 2 Pi}, PlotRange -> {{-0.4, 0.4}, {0, 6}}, 
      AspectRatio -> 1, ImageSize -> 200, AxesLabel -> {"x", "t"}];
pl3 = ParametricPlot[{t, ss'[t]}, {t, 0, 2 Pi}, PlotRange -> {{0, 6}, {-2, 1}}, 
      AspectRatio -> 1, ImageSize -> 200, AxesLabel -> {"t", "y"}];

Since you are using similar PlotRange simple Grid should work nicely. If you need to do some manual adjustment, use Manipulate to find best ImagePadding and then use the final output plotall.

Manipulate[
p1 = Show[pl1, ImagePadding -> b0];
p2 = Show[pl2, ImagePadding -> {{bx1, bx2}, {b0, b0}}];
p3 = Show[pl3, ImagePadding -> {{b0, b0}, {by1, by2}}];
plotall = Grid[{{p2,}, {p1, p3}}, Spacings -> 0],
{{b0, 20}, 0, 100},
{{bx1, 20}, 0, 100}, {{bx2, 20}, 0, 100},
{{by1, 20}, 0, 100}, {{by2, 20}, 0, 100}]

plotall

enter image description here

$\endgroup$
1
  • $\begingroup$ if the PlotRange of v and h-axes of each plot must be specified differently, how to fix the problem? $\endgroup$
    – Liang.X
    Dec 25, 2016 at 17:12
15
$\begingroup$
f1 = {y''[t] == -9.82 Sin[y[t]] + 1.5 (y[t] - y'[t]), y[0] == 1, 
   y'[0] == 0};
ss[t_] = y[t] /. NDSolve[f1, y, {t, 0, 10}][[1]]
fun[p_] := 
 Show[Plot[ss'[t - 1], {t, 1, 2 Pi + 1}, PlotRange -> Full], 
  ParametricPlot[{ss[t], ss'[t]}, {t, 0, 2 Pi}],
  ParametricPlot[{ss[t - 2], -t}, {t, 2, 2 Pi + 2}]
  , PlotRange -> {{-1, 6}, {-8, 1}}, AxesOrigin -> {0, 0}, 
  GridLines -> {{ss[p]}, {ss'[p]}}, 
  Epilog -> {Red, PointSize[0.02], 
    Point[{{ss[p], ss'[p]}, {p + 1, ss'[p]}, {ss[p], -p - 2}}]}]

Animated gif from table of fun[p]:

enter image description here

$\endgroup$
2
  • $\begingroup$ could the top-right and bottom-left graphics be plotted seperately with their own axes and labels? $\endgroup$
    – Liang.X
    Dec 25, 2016 at 17:17
  • $\begingroup$ @Liang.X I did this to make alignment work (as demonstrated) by grid lines. You could customize ticks to give 'correct' values of t. I leave that to you. Happy holidays:) $\endgroup$
    – ubpdqn
    Dec 25, 2016 at 19:34

Your Answer

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

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