4
$\begingroup$

I am trying to combine two plots in a way that the second plot will horizontally move to the point where the first one ends. So they will be touching each other at their end/starting points. I have tried some simple tricks and codes, but no success. The codes are as the followings:

Fig1 := Plot[10.9545 + Sqrt[100 - x^2]/2, {x, 0, 16}, PlotRange -> {{0, 16}, {0, 16}}];

Fig2 := Plot[Sqrt[120.` - 4.` x^2], {x, 0, 6}];

Show[Fig1, Fig2, DisplayFunction -> $DisplayFunction,PlotLabel -> "Combined PPF"]

enter image description here

$\endgroup$
7
$\begingroup$

You can use Translate to translate the graphics primitives of Fig2 by a vector of your choice:

Show[Fig1, Fig2 /. l_Line :> Translate[l, {10, 0}], PlotRange -> All] (* or *)
Show[Fig1, Graphics[Translate[Fig2[[1]], {10, 0}]], PlotRange -> All]

enter image description here

Alternatively, you create a translated version of Fig2:

Fig3 = Plot[Sqrt[120.` - 4.` (x - 10)^2], {x, 10, 16}];
Show[Fig1, Fig3, PlotRange -> All]

same picture

$\endgroup$
2
  • $\begingroup$ Thanks! Translate is the one that I have been looking for. $\endgroup$
    – Ilker
    Aug 26 '18 at 16:53
  • $\begingroup$ `@Ilker, my pleasure. Thank you for the accept. $\endgroup$
    – kglr
    Aug 26 '18 at 16:53
5
$\begingroup$

An alternative is to define your function as having two parts using Piecewise, and then simply plot that combined function.

f[x_] := Piecewise[{{10.9545 + Sqrt[100 - x^2]/2, 0 < x < 10},
                    {Sqrt[120.` - 4.` (x - 10)^2], 10 < x < 16}}];
Plot[f[x], {x, 0, 16}]

enter image description here

$\endgroup$

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.