I have some lines of code that generate numerical solutions to equations. Then I want to combine two of these in a piecewise function. The way I did it is the following -lf1[r] and lf4[r] are the aforementioned numerical solutions
test[r_] :=
Piecewise[{{lf1[r], 0.688199 <= r <= 10}, {lf4[r],
0.687159 <= r <= 0.688199}}]
Show[Plot[test[r], {r, 0.676319, rmax}, PlotStyle -> {Thick},
BaseStyle -> {18, FontFamily -> "Times New Roman"},
AxesLabel -> {"\[Rho]", "L(\[Rho])"},
PlotRange -> {{0, rmax}, {0, 1.4}}],
Plot[x, {x, 0, 1.4}, PlotStyle -> {Thick, Black}]]
The plot is the following
Then I would like to have different colours in the different sectors of the piecewise function. I found some excellent answers here and I tried to adopt them - particularly in this link. However, I am facing some difficulties that I do not understand.
Example 1: Different colours, wrong plot.
pwSplit[_[pairs : {{_, _} ..}]] :=
Piecewise[{#}, Indeterminate] & /@ pairs
pwSplit[_[pairs : {{_, _} ..}, expr_]] :=
Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}]
pw = Piecewise[{{lf4[r], 0.687159 <= r <= 0.688199}, {lf1[r],
0.688199 <= r <= 10}}];
Plot[Evaluate[pwSplit@pw], {r, 0, 1}, PlotStyle -> Thick,
Axes -> True]
Example 2: This time I don't get many colours and I also get a wrong plot -if you see there is a black flat line in the bottom that should not be there
f = Piecewise[{{lf1[#], 0.688199 <= # <= 10}, {lf4[#],
0.687159 <= # <= 0.688199}}] &;
colorFunction = f;
piecewiseParts = Length@colorFunction[[1, 1]];
colors = ColorData[1][#] & /@ Range@piecewiseParts;
colorFunction[[1, 1, All, 1]] = colors;
Show[Plot[f[x], {x, 0, 10}, ColorFunction -> colorFunction,
ColorFunctionScaling -> False, PlotRange -> {{0, rmax}, {0, 1.4}},
PlotStyle -> {Thick}],
Plot[x, {x, 0, 1.4}, PlotStyle -> {Thick, Black}]]
I don't understand what I am doing wrong in either case and it is not clear if I should modify something due to the fact that I have numerical functions and not analytic.