1

I am plotting a function using DensityPlot for two different values of a parameter. I am setting the PlotLegends option to Automatic. The output I get gives me two density plots; one of whose ranges goes from 0.05 to 0.20 and the second one ranges from -0.25 to 0.75.

However, in the final output I want a DensityPlot whose range goes from -0.5 to 1 so that the color for both plots is synchronized. I would really appreciate if someone could let me know how to do this. Here is the code I am using.

Clear[f, g, h, p, r, l, jac, u1, u2, u3, u4, G, x, y, z, sol, xinit, yinit, zinit, plotfunc0, plotfunc1, A, r1, r2]
r = 0.1;    
r2 = 0.9;
G = {{15, 15, 15, 6}, {10, 10, 10, 1}, {10, 10, 10, 1}, {16, 16, 16, 
   7}};

u1[A_, De_] = G[[1, 1]](1 - A)(1 - De) + G[[1, 2]](1 - A)De + G[[1, 3]]A(1 - De) + G[[1, 4]]ADe ; u2[A_, De_] = G[[2, 1]](1 - A)(1 - De) + G[[2, 2]](1 - A)De + G[[2, 3]]A(1 - De) + G[[2, 4]]ADe ; u3[A_, De_] = G[[3, 1]](1 - A)(1 - De) + G[[3, 2]](1 - A)De + G[[3, 3]]A(1 - De) + G[[3, 4]]ADe ; u4[A_, De_] = G[[4, 1]](1 - A)(1 - De) + G[[4, 2]](1 - A)De + G[[4, 3]]A(1 - De) + G[[4, 4]]ADe ; ualpha[A_, De_] = ((1 - A)(1 - De)u1[A, De]) + ((1 - A)De u2[A, De]) + (A(1 - De)u3[A, De]) + (ADeu4[A, De]); us[A_, De_] = ((1 - A)(1 - De)u1[A, De]) + ((1 - A)De u2[A, De]); ua[A_, De_] = (A(1 - De)u3[A, De]) + (ADeu4[A, De]); uc[A_, De_] = ((1 - A)(1 - De)u1[A, De]) + (A(1 - De)u3[A, De]); ud[A_, De_] = ((1 - A)De u2[A, De]) + (ADe u4[A, De]); F1[A_, De_] = ((1 - r)(1 - A)(1 - De)u1[A, De]/ualpha[A, De]) + (r us[A, De]uc[A, De]/((ualpha[A, De])^2)) - ((1 - A)(1 - De)); F2[A_, De_] = ((1 - r)(1 - A)Deu2[A, De]/ualpha[A, De]) + (r us[A, De]ud[A, De]/((ualpha[A, De])^2)) - ((1 - A)De); F3[A_, De_] = ((1 - r)A(1 - De)u3[A, De]/ualpha[A, De]) + (r ua[A, De]uc[A, De]/((ualpha[A, De])^2)) - (A(1 - De)); scG[A_, De_] = F1[A, De]/((1 - A)(1 - De)); adG[A_, De_] = ( -F1[A, De] - F2[A, De] - F3[A, De])/(ADe); netG[A_, De_] = -scG[A, De] + adG[A, De]; G1[A_, De_] = ((1 - r2)(1 - A)(1 - De)* u1[A, De]/ualpha[A, De]) + (r2us[A, De] uc[A, De]/((ualpha[A, De])^2)) - ((1 - A)(1 - De)); G2[A_, De_] = ((1 - r2)(1 - A)Deu2[A, De]/ualpha[A, De]) + (r2* us[A, De]ud[A, De]/((ualpha[A, De])^2)) - ((1 - A)De); G3[A_, De_] = ((1 - r2)A(1 - De)u3[A, De]/ualpha[A, De]) + (r2 ua[A, De]uc[A, De]/((ualpha[A, De])^2)) - (A(1 - De)); scG2[A_, De_] = G1[A, De]/((1 - A)(1 - De)); adG2[A_, De_] = ( -G1[A, De] - G2[A, De] - G3[A, De])/(ADe); netG2[A_, De_] = -scG2[A, De] + adG2[A, De]; DensityPlot[netG[A, DE], {A, 0, 1}, {DE, 0, 1}, PlotLegends -> Automatic, FrameTicksStyle -> Directive[FontSize -> 14]] DensityPlot[netG2[A, DE], {A, 0, 1}, {DE, 0, 1}, PlotLegends -> Automatic, FrameTicksStyle -> Directive[FontSize -> 14]]

Density plot 1

Density plot 2

Syed
  • 52,495
  • 4
  • 30
  • 85
egt123
  • 165
  • 5

1 Answers1

1
g1 = DensityPlot[netG[A, DE], {A, 0, 1}, {DE, 0, 1}
   , ColorFunction -> (ColorData["M10DefaultDensityGradient"][
       Rescale[#, {-0.5, 1.0}]] &)
   , ColorFunctionScaling -> False
   , FrameTicksStyle -> Directive[FontSize -> 14]
   ];

g2 = DensityPlot[netG2[A, DE], {A, 0, 1}, {DE, 0, 1}
   , ColorFunction -> (ColorData["M10DefaultDensityGradient"][
       Rescale[#, {-0.5, 1.0}]] &)
   , ColorFunctionScaling -> False
   , FrameTicksStyle -> Directive[FontSize -> 14]
   ];

legend = BarLegend[{"M10DefaultDensityGradient", {-0.5, 1}}
   , LegendLayout -> "Column"
   , LegendMarkerSize -> 246];

Labeled[
 GraphicsRow[{g1, g2, legend}]
 , Grid[{{"NetG", "NetG2", "Range"}}
  , ItemSize -> {{19, 19, 4}, 1}
  , Alignment -> Center
  , Frame -> None
  ] (*end of Grid*)
 , Top
 ]

enter image description here

Syed
  • 52,495
  • 4
  • 30
  • 85