2
$\begingroup$

Consider the code for the bifurcation diagram:

res = Internal`Bag[]; tmax = 5; {x0, y0, z0} = {1, 1, 1}; 

Suppose I define p1 as:

p1 = Do[sol = NDSolve[{x'[t] == 10 (y[t] - x[t]), y'[t] == (r*1) x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 4 z[t], x[0] == x0, y[0] == y0, z[0] == z0,(*save extrema of z[t]*) WhenEvent[z'[t] == 0, Internal`StuffBag[res, {r, z[t]}]]}, {x, y, z}, {t, 0, tmax}][[1]];{x0, y0, z0} = {x[tmax], y[tmax], z[tmax]} /. sol;, {r, 1, 200, 0.5}]; ListPlot[Internal`BagPart[res, All], PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}, AxesLabel -> {"r", "z"}, Frame -> {{True, True}, {True, False}}, FrameLabel -> {"r", "Z"}] 

and p2 as:

p2 = Do[sol = NDSolve[{x'[t] == 9 (y[t] - x[t]), y'[t] == (r*2) x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 5 z[t], x[0] == x0, y[0] == y0, z[0] == z0,(*save extrema of z[t]*) WhenEvent[z'[t] == 0, Internal`StuffBag[res, {r, z[t]}]]}, {x, y, z}, {t, 0, tmax}][[1]];{x0, y0, z0} = {x[tmax], y[tmax], z[tmax]} /. sol;, {r, 1, 200, 0.5}]; ListPlot[Internal`BagPart[res, All], PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}, AxesLabel -> {"r", "z"}, Frame -> {{True, True}, {True, False}}, FrameLabel -> {"r", "Z"}] 

How can I merge p1 and p2 with a common x-axis as shown in this plot: https://i.sstatic.net/UXZnF8ED.png

Any help would be really appreciated.

$\endgroup$
1
  • $\begingroup$ Ummm... Plot[{f[x],g[x]},{x,0,1}]...? $\endgroup$ Commented May 1, 2024 at 21:12

1 Answer 1

2
$\begingroup$
$Version (* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *) Clear["Global`*"] res = Internal`Bag[]; tmax = 5; {x0, y0, z0} = {1, 1, 1}; p1 = Do[sol = NDSolve[{x'[t] == 10 (y[t] - x[t]), y'[t] == (r*1) x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 4 z[t], x[0] == x0, y[0] == y0, z[0] == z0,(*save extrema of z[t]*) WhenEvent[z'[t] == 0, Internal`StuffBag[res, {r, z[t]}]]}, {x, y, z}, {t, 0, tmax}][[1]]; {x0, y0, z0} = {x[tmax], y[tmax], z[tmax]} /. sol;, {r, 1, 200, 0.5}]; lp1 = ListPlot[Internal`BagPart[res, All], PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}, Frame -> True, FrameLabel -> {"r", "Z"}]; 

EDIT: Reset definition of res for second plot

res = Internal`Bag[]; p2 = Do[sol = NDSolve[{x'[t] == 9 (y[t] - x[t]), y'[t] == (r*2) x[t] - y[t] - x[t] z[t], z'[t] == x[t] y[t] - 5 z[t], x[0] == x0, y[0] == y0, z[0] == z0,(*save extrema of z[t]*) WhenEvent[z'[t] == 0, Internal`StuffBag[res, {r, z[t]}]]}, {x, y, z}, {t, 0, tmax}][[1]]; {x0, y0, z0} = {x[tmax], y[tmax], z[tmax]} /. sol;, {r, 1, 200, 0.5}]; lp2 = ListPlot[Internal`BagPart[res, All], PlotStyle -> {Gray, Opacity[0.1], PointSize[0.001]}, Frame -> True, FrameLabel -> {"r", "Z"}]; 

With version 12 or later use ResourceFunction["PlotGrid"]

ResourceFunction["PlotGrid"][{{lp1}, {lp2}}] 

enter image description here

$\endgroup$
4
  • $\begingroup$ There are two bifurcation diagrams on the bottom-plot. That seems to be an error $\endgroup$ Commented May 2, 2024 at 0:33
  • $\begingroup$ They' re your plots . I merely showed you how to stack them. Presumably, you want to reset definition of res as shown in edit. $\endgroup$ Commented May 2, 2024 at 3:28
  • $\begingroup$ It is perfect now. Thank you! $\endgroup$ Commented May 2, 2024 at 6:17
  • $\begingroup$ Also with the use of Frame -> {{True, True}, {False, True}} in p1 and Frame -> {{True, True}, {True, False}} in p2, we get the plot with a common x-axis. $\endgroup$ Commented May 2, 2024 at 6:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.