2
$\begingroup$

Hello colleagues!!

I have an issue with the Filling parameter in a ListPlot. I constructed an equilateral triangle of length 1, where I plot some points in barycentric coordinates, describing a curve and a line when joined. Here's a view:

Figure 1

For the model I'm describing, I need to fill with color the upper right region, inside the triangle, defined by a segment of the red line, a segment of the blue curve, and a segment of the right side of the triangle. The region seems like a right triangle, the hipotenuse being 'curve' (actually, the red line and the right side of the triangle are perpendicular).

I tried to use the Filling option of the ListPlot command, but I'm almost convinced that it's impossible to fill the described region using Filling. I'm currently working on another approach to put color in this region, but I think this could be a nice problem for anyone of you. Hats off for the one who can solve it, and thank you in advance!!

Daniel

PD: Here's some code to replicate the exact figure:

k1 = Table[0.01 i, {i, 0, 100}];
yLine = k1 Sqrt[3]/2;
xLine = (Sqrt[3] k1 + yLine)/Sqrt[3];
k3 = Table[
  Solve[{x k1[[i]] == y 1/4, k1[[i]] + x + y == 1}, {x, y}], {i, 
   1, 101}][[All, 1]][[All, 1]][[All, 2]];
k4 = Table[
  Solve[{x k1[[i]] == y 1/4, k1[[i]] + x + y == 1}, {x, y}], {i, 
   1, 101}][[All, 1]][[All, 2]][[All, 2]];
yCurve = k3 Sqrt[3]/2;
xCurve = (Sqrt[3] k4 + yCurve)/Sqrt[3];
leftSide = Table[Sqrt[3] k1[[i]], {i, 1, 51}];
rightSide = Table[-Sqrt[3] (k1[[i]] - 1), {i, 51, 101}];
bottomSide = Table[0, {i, 1, 101}];
ListPlot[{Transpose[{k1, bottomSide}], 
  Transpose[{k1[[1 ;; 51]], leftSide}], 
  Transpose[{k1[[51 ;; 101]], rightSide}], Transpose[{xLine, yLine}], 
  Transpose[{xCurve, yCurve}]}, AspectRatio -> Sqrt[3]/2, 
  PlotRange -> {{0, 1}, {0, Sqrt[3]/2}}, Joined -> True, 
  PlotStyle -> {Black, Black, Black, Red, Blue}]
$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey May 17 '15 at 16:35
  • 1
    $\begingroup$ perhaps Filling -> {4 -> {{3}, {Blue, None}}, 4 -> {{5}, White}}? $\endgroup$ – kglr May 17 '15 at 17:40
7
$\begingroup$
lines = {{{0, 0}, {0, 1}}, {{0, 0}, {1/2, Sqrt[3]/2}}, 
         {{1/2, Sqrt[3]/2}, {1, 0}}, {{0, 0}, {1, 1/2}}};
curve = Join @@ ({y + x /2, Sqrt[3] x/2} /. 
     Table[Solve[{x k1[[i]] == y 1/4, k1[[i]] + x + y == 1}, {x, y}], {i, 1, 101}]);

ListLinePlot[{## & @@ lines, curve}, AspectRatio -> Sqrt[3]/2, 
 PlotRange -> {{0, 1}, {0, Sqrt[3]/2}}, 
 PlotStyle -> {Black, Black, Black, Red, Blue},
 Filling -> {4 -> {{3}, {Yellow, None}}, 4 -> {{5}, White}}]

Mathematica graphics

For non-white Background, change White to the background color:

ListLinePlot[{## & @@ lines, curve}, AspectRatio -> Sqrt[3]/2, 
 PlotRange -> {{0, 1}, {0, Sqrt[3]/2}}, 
 PlotStyle -> {Black, Black, Black, Red, Blue}, Background -> Cyan,
 Filling -> {4 -> {{3}, {Yellow, None}}, 4 -> {{5}, Cyan}}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ One might also choose to use Transparent instead of White for the fill if the background of the plot were not white. $\endgroup$ – J. M. will be back soon May 17 '15 at 18:17
  • $\begingroup$ @Guesswhoitis., Transparent instead of White does not cover the piece we need to cover. To deal with non-white Background, we need to use the background color in place of White. $\endgroup$ – kglr May 17 '15 at 18:26
  • $\begingroup$ Ah, after reading the docs for Filling I realized it now. Thanks for the correction! $\endgroup$ – J. M. will be back soon May 17 '15 at 18:28
  • $\begingroup$ Thanks kguler, you did it!! :-) $\endgroup$ – cricricombowino May 18 '15 at 19:11
  • $\begingroup$ @cricricombowino, my pleasure. Welcome to mma.se. $\endgroup$ – kglr May 18 '15 at 19:42

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.