0
$\begingroup$

I am trying to generate a set of StreamPlots that show a system of ordinary differential equations bifurcating for various values of a parameter. The code (in its entirety) is as follows

ClearAll["Global`*"]

(*Put in ODE system for fixed m*)

m=1/3;
g[p_,f_,m_,Z_,n_]:=(3n^2 m-(n-1)^2 (n+2))Z^-1 p-3n^2 Z^-1 f p; 
h[p_,f_,n_]:=-8f+2n^6 p^2;

(*Solve for the critical points*)

equilibria=Solve[{g[p,f,m,Z,n]==0,h[p,f,n]==0},{p,f}];

(*Plot critical points, nullclines and streamplot for fixed r, s, Z*)

r=0.9; s=10;
Z=r+s^-1 n^4;

Table[Show[StreamPlot[{g[p,f,m,Z,n],h[p,f,n]},{p,-4/10,4/10},{f,-1/10,1/2},StreamScale->0.1,FrameTicks->None,ImageSize->{Automatic,300},FrameLabel->{,,f,Rotate["p",-90 Degree]}],
ContourPlot[{g[p,f,m,Z,n]==0,h[p,f,n]==0},{p,-4/10,4/10},{f,-1/10,1/2},ContourStyle->Blue],
ListPlot[{p,f}/.equilibria,PlotStyle->{Red,PointSize[0.03]}],Frame->True,Axes->False],{n,2.1,1.6,-0.1}]

The resulting plots are then outputted as a sequence of individual plots in the Mathematica notebook. What I would like to do is to make it so the outputted plots are plotted in three columns of two (corresponding to the six bifurcation diagrams being plotted for the six values of $n$) with no whitespace in between the plots. However, I do not know how to do this (I'm very new to Mathematica). I tried using PlotLayout i.e

[..., ListPlot[{p,f}/.equilibria,PlotStyle->{Red,PointSize[0.03]}],Frame->True,Axes->False,PlotLayout->{"Column",3}]

but this did nothing.

So, my question is is it possible to construct the plots in such a way as to have no whitespace between the plots and in three columns?

$\endgroup$

1 Answer 1

1
$\begingroup$
ClearAll["Global`*"]

(*Put in ODE system for fixed m*)

m = 1/3;
g[p, f_, m, Z, n_] := (3 n^2 m - (n - 1)^2 (n + 2)) Z^-1 p - 
   3 n^2 Z^-1 f p;
h[p, f_, n_] := -8 f + 2 n^6 p^2;

(*Solve for the critical points*)

equilibria = Solve[{g[p, f, m, Z, n] == 0, h[p, f, n] == 0}, {p, f}];

(*Plot critical points,nullclines and streamplot for fixed r,s,Z*)

r = 0.9; s = 10;
Z = r + s^-1 n^4;

plots = Table[
   Show[
    StreamPlot[{
      g[p, f, m, Z, n],
      h[p, f, n]},
     {p, -4/10, 4/10}, {f, -1/10, 1/2},
     StreamScale -> 0.1, FrameTicks -> None, 
     ImageSize -> {Automatic, 300}, 
     FrameLabel -> {, , f, Rotate["p", -90 Degree]}],
    ContourPlot[{
      g[p, f, m, Z, n] == 0,
      h[p, f, n] == 0},
     {p, -4/10, 4/10}, {f, -1/10, 1/2},
     ContourStyle -> Blue],
    ListPlot[{
       p,
       f
       } /. equilibria, PlotStyle -> {Red, PointSize[0.03]}], 
    Frame -> True, Axes -> False], {n, 2.1, 1.6, -0.1}];

Grid[{
  {plots[[1]], plots[[2]], plots[[3]]},
  {plots[[4]], plots[[5]], plots[[6]]}
  }]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you for your help. Sorry, I accidentally removed the underscores for $p, m, Z$ in the definition of $g$ and for $p$ in the definition of $h$ because I changed the variable names from what I have in my notebook and so the StreamPlot and nullclines didn't plot. I found something similar just before you made your post using GraphicsGrid which works great. To get rid of the whitespace, using GraphicsGrid, you can use the Spacings option to remove the white. Thanks for your help. $\endgroup$ Jul 5, 2022 at 19:11

Your Answer

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

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