An alternative trick is to add a semi-transparent rectangle as Epilog
:
With[{a1 = 1, a2 = 2, a = 3, b1 = 1, b2 = 2, b = 3, lag1 = 26,
lag = 30, time1 = 40, time2 = 36, time3 = 39},
p1 = Plot[a Sqrt[x] - b Cos[x], {x, 0, time1}, PlotStyle -> Blue];
p2 = Plot[a1 Sqrt[x] - b1 Cos[x], {x, time1 - lag, time2}, PlotStyle -> Red];
p3 = Plot[a2 Sqrt[x] - b2 Cos[x], {x, time2 - lag1, time3}, PlotStyle -> Green];
Show[p1, p2, p3,
Epilog -> {Opacity[.8, White], Rectangle[{15, .5}, {40, 40}]},
GridLines -> {{15}, None},
GridLinesStyle -> Directive[Gray, Dashed], PlotRange -> All]]
You can also use the option ColorFunction
:
An alternative trick isUpdate: We can use the last approach to add a semi-transparent rectangle as Epilog
have different thresholds in the three plots:
With[DynamicModule[{a1 = 1, a2 = 2, a = 3, b1 = 1, b2 = 2, b = 3,
lag1 = 26,
lag = 30, time1 = 40, time2 = 36, time3 = 39,
thresholds = {15, 20, 25}},
p1 = Plot[a Sqrt[x] - b Cos[x], {x, 0, time1}, PlotStyleMesh -> Blue];{{15}},
ColorFunctionScaling -> False,
ColorFunction -> twoToneCF[thresholds[[1]], Blue]];
p2 = Plot[a1 Sqrt[x] - b1 Cos[x], {x, time1 - lag, time2}, PlotStyle
ColorFunctionScaling -> Red];False,
ColorFunction -> twoToneCF[thresholds[[2]], Red]];
p3 = Plot[a2 Sqrt[x] - b2 Cos[x], {x, time2 - lag1, time3}, PlotStyle
-> Green];
Show[p1,ColorFunctionScaling p2,-> p3False,
Epilog ColorFunction -> {Opacity[.8, White]twoToneCF[thresholds[[3]], Rectangle[{15,Green]];
0}Show[p1, {40p2, 40}]}p3,
GridLines -> {Thread[{15thresholds, {Blue, Red, Green}}], None},
GridLinesStyle -> Directive[Gray, Dashed], PlotRange -> All]]
NoteAn aside: You might want top play with ConditionalExpression
and Piecewise
to get all three plots using a single Plot
.