0
$\begingroup$

enter image description here

How can I change the position of the labels in ListLinePlot to be on the left-hand side of the curves instead of the right-hand side? In addition, how can I make the labels to appear just for two of the curves, not all of them?

In the following, I am plotting the solutions of NSolve, while labeling each curve with the value of a parameter (a) which is specific for that curve.

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, 
     PlotLabels -> 
      Placed[Flatten[{x[[1]], ConstantArray["", Length[x] - 3], 
         x[[-2]], ""}], Left], 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]
$\endgroup$
  • $\begingroup$ Why doesn't v = Table[{\[Tau]4, \[Tau]3, \[Tau]2, \[Tau]1} /. aR]; have a second argument? (slightly unrelated to your main question) $\endgroup$ – user6014 Aug 26 '17 at 1:07
  • $\begingroup$ A starting point could be PlotLabels -> Callout[Values@x, Before], but I didn't manage to get MMA to spread them nicely so that they don't overlap. $\endgroup$ – Lukas Lang Aug 26 '17 at 12:15
  • 1
    $\begingroup$ As for omitting some of them: Simply put None in the list of labels, i.e. PlotLabels -> {Label1, Label2, None, Label4, None, ...} $\endgroup$ – Lukas Lang Aug 26 '17 at 12:18
  • $\begingroup$ Spent some time on this, it seems to be very difficult to move the labels properly to the left. Placed[..., Left] should work, but it always looks terrible. $\endgroup$ – user6014 Aug 26 '17 at 15:30
  • $\begingroup$ I have corrected the second argument of Table. But can't get the correct labels yet! PlotLabels seems to be not available for ListLinePlot in Version 10! $\endgroup$ – Hossein Aug 26 '17 at 21:23
1
$\begingroup$

time for a little trick: since you don't have PlotLabels i suggest you to use Inset to achieve a similar result

use Epilog-> Inset to insert the text you want in the position {x,y}.

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}, 
     Epilog -> 
      Inset[Style[StringJoin["a = " , ToString[Values[x][[1]]]], Red], {1, 
        0.73}]], "Income Brackets"]

  ]


f[set]

Update: the number in the image is wrong but the code is now fixed

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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