# Plotting NSolve solution by ListLinePlot

I am trying to plot the values of the solution to NSolve: {τ4, τ3, τ2, τ1} by connected lines, while each line shows these 4 values for a specific value of the parameter (a)? But in the following codes, it seems that NSolve doesn't recognize the values of the parameter (a), specified by:

set = a -> # & /@ Range[0, 3, 0.5];


In addition, for the labels, is there a way to show just the first one (a=0) and the sixth one (a=0.5) on the curves, instead of all labels, and also on the left hand side of the curves instead of the right-hand side?

gamma4 = .4;
gamma3 = .284;
gamma2 = .265;
gamma1 = .484;
z3 = 10000;
z2 = 32000;
z1 = 75000;
zbar4 = 4800;
zbar3 = 20050;
zbar2 = 46200;
zbar1 = 138100;
h4 = .301;
h3 = .404;
h2 = .25;
h1 = .045;
p1 = 3.89;
p2 = 4.92;
p3 = 5.22;
p4 = 5.39;
g1 = 0;
g2 = 0.44;
g3 = 0.88;
g4 = 1.76;

eq1 = (\[Tau]1/(1 - \[Tau]1)) - ((1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) (zbar1 -
z1)/((1 - ((g1 a p1/\[Tau]1) + g2 a p2 + g3 a p3 +
g4 a p4)) zbar1 gamma1));
Print["0=", eq1];

eq2 = (\[Tau]2/(1 - \[Tau]2)) - (((1 -
g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 (zbar2 - z2) + (1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) h1 (z1 -
z2))/((1 - (g1 a p1 + (g2 a p2/\[Tau]2) + g3 a p3 +
g4 a p4)) (zbar2 h2 gamma2)));
Print["0=", eq2];

eq3 = (\[Tau]3/(1 - \[Tau]3)) - (((1 -
g3 - (g1 a p1 + g2 a p2 + g4 a p4)) h3 (zbar3 -
z3) + ((1 - g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 + (1 -
g1 - (g2 a p2 + g3 a p3 + g4 a p4)) h1) (z2 -
z3))/((1 - (g1 a p1 + g2 a p2 + (g3 a p3/\[Tau]3) +
g4 a p4)) zbar3 h3 gamma3));
Print["0=", eq3];

eq4 = (\[Tau]4/(1 - \[Tau]4)) - (((1 -
g4 - (g1 a p1 + g2 a p2 +
g3 a p3)) h4 (zbar4) + ((1 -
g3 - (g1 a p1 + g2 a p2 + g4 a p4)) h3 + (1 -
g2 - (g1 a p1 + g3 a p3 + g4 a p4)) h2 + (1 -
g1 - (g2 a p2 + g3 a p3 +
g4 a p4)) h1) z3)/((1 - (g1 a p1 + g2 a p2 +
g3 a p3 + (g4 a p4/\[Tau]4))) zbar4*h4*gamma4));
Print["0=", eq4];

set = a -> # & /@ Range[0, 3, 0.1];

f[x_] := Module[{v},
v = Table[{\[Tau]4, \[Tau]3, \[Tau]2, \[Tau]1} /.
NSolve[{eq1 == 0, eq2 == 0, eq3 == 0,
eq4 == 0 && \[Tau]1 > 0 && \[Tau]2 > 0 && \[Tau]3 >
0 && \[Tau]4 > 0} /.
x[[i]], {\[Tau]1, \[Tau]2, \[Tau]3, \[Tau]4}], {i, 1,
Length[x], 1}]; v = Flatten[v, 1];
mR = Labeled[
ListLinePlot[v, GridLines -> {None, {1}},
GridLinesStyle ->
Directive[
AbsoluteThickness[3/2] ColorData[97,
2] Method -> {"GridLinesInFront" -> True}],
PlotLabel -> Style["MTR- Rawlsian", FontSize -> 18],
PlotRange -> {0, 1.05}, PlotLegends -> Values@x,
PlotMarkers -> {Automatic, 10},
Ticks -> {{{1, zbar4}, {2, zbar3}, {3, zbar2}, {4, zbar1}}, {0.2,
0.4, 0.6, 0.8, 0.9, 1}},
TicksStyle -> {Directive[Red, 12], Directive[Red, 8]},
ImageSize -> {800, 300}], "Income Brackets"]]

f[set]


You want to replace the parameters with numbers in your equations before you solve them numerically. Closest to your current approach is just moving where you apply your replacement rule to inside NSolve:

  v = Table[{τ4, τ3, τ2, τ1} /.
NSolve[{eq1 == 0, eq2 == 0, eq3 == 0,
eq4 == 0 && τ1 > 0 && τ2 > 0 && τ3 >
0 && τ4 > 0} /.
x[[i]], {τ1, τ2, τ3, τ4}], {i, 1,
Length[x], 1}];


Regarding your labels question. To suppress Legend labels you can set them to None. Placement of PlotLegends is controlled with Placed so perhaps something like:

PlotLegends ->
Placed[Flatten[{x[[1, 2]], ConstantArray[None, Length[x] - 2],
x[[-1, 2]]}], Left]


Update: Specifically for PlotLabels: PlotLabels will actually print None if given as an argument, so instead you can give it empty strings for labels you don't want. Specifically to only visibly label first and sixth:

PlotLabels ->
Placed[Flatten[{x[[1]], ConstantArray["", Length[x] - 3], x[[-2]],
""}], Left]


Update${}^2$: For Version 10, can hack something together with Text Graphics directives. i.e.

Show[ListLinePlot[v, GridLines -> {None, {1}},
GridLinesStyle ->
Directive[
AbsoluteThickness[3/2] ColorData[97,
2] Method -> {"GridLinesInFront" -> True}],
PlotLabel -> Style["MTR- Rawlsian", FontSize -> 18],
PlotRange -> Automatic, PlotMarkers -> {Automatic, 10},
Ticks -> {{{1, zbar4}, {2, zbar3}, {3, zbar2}, {4, zbar1}}, {0.2,
0.4, 0.6, 0.8, 0.9, 1}},
TicksStyle -> {Directive[Red, 12], Directive[Red, 8]},
Joined -> True],
Graphics[{Text[x[[1]], {.75, v[[1, 1]]} + {0, .005}],
Text[x[[6]], {.75, v[[6, 1]]} + {0, .005}]}]]


yields:

• Best bet is just Text graphics directives by hand exactly where you want them, but I'll add the most "automatic" PlotLabels which is "" instead of None. Aug 26, 2017 at 21:01
• Thanks @John! Just PlotLabels stays red when I add it beside the other options of ListLinePlot! Aug 26, 2017 at 21:14
• It's a valid option: Position[Options[ListLinePlot], PlotLabels] has it as the 46th option in Version 11.1. Aug 26, 2017 at 21:17
• Oh! Mine is Version 10, and it's not in the options! Aug 26, 2017 at 21:20
• Updated to give example of how you can use text directives even in V10. Aug 26, 2017 at 21:40