0
$\begingroup$

I'm plotting the graph below using the following code. The problem is that I need to make the area between the green and red curve shaded, but I can't make this work using Filling. I'd appreciate any ideas. (Have already tried the solution in here, which fails strangely because it only plots the left half of the red line)

enter image description here

    x = d;
    y = d^2;
    z = Max[0, 2 (d - 1/2)];
    p1 = Plot[x, {d, 0, 1}, PlotLegends -> Placed[LineLegend[{
RGBColor[0.368417, 0.506779, 
        0.709798]}, {"Assignment by lottery"}], {0.282, 0.8}], 
   PlotStyle -> RGBColor[0.368417, 0.506779, 0.709798]];

    p2 = Plot[y, {d, 0, 1}, PlotLegends -> Placed[LineLegend[{
RGBColor[0.560181, 0.691569, 
        0.194885]}, {"Complete equality"}], {0.25, 0.9}], 
   PlotStyle -> RGBColor[0.560181, 0.691569, 0.194885]];

    p3 = Plot[z, {d, 0, 1}, PlotLegends -> Placed[LineLegend[{
RGBColor[0.922526, 0.385626, 0.209179]}, {"FCFS"}], {0.145, 0.7}], 
   PlotStyle -> RGBColor[0.922526, 0.385626, 0.209179]];

    Show[{p2, p1, p3}, AxesLabel -> {F[t], Subscript[L, P][F[t]]}, 
 LabelStyle -> Directive[{FontColor -> Black}, {FontSize -> 16}]]
$\endgroup$
6
  • 4
    $\begingroup$ Please, post the code not an image. $\endgroup$
    – yarchik
    May 27 '20 at 6:32
  • 4
    $\begingroup$ Filling->{2->{3}} $\endgroup$ May 27 '20 at 7:01
  • $\begingroup$ Have you tried doing it all under a single Plot? (I'd try it myself, but without the code here as text, I can't try it out and modify it without manually retyping everything...that's why it's always useful to post code, not images of code! :) ) $\endgroup$
    – thorimur
    May 27 '20 at 7:59
  • $\begingroup$ @yarchik Thank you, I now copy the code $\endgroup$
    – afshi7n
    May 27 '20 at 23:08
  • 1
    $\begingroup$ @thorimur Thank you. I now have copied the code instead of the image. The reason I didn't use a single plot is that I set different specifications for p1,p2,p3 plots, and I don't know how to do that in a single plot comment.. $\endgroup$
    – afshi7n
    May 27 '20 at 23:11
2
$\begingroup$
Plot[{x, y, z}, {d, 0, 1}, Filling -> {3 -> {2}}, 
 PlotLegends -> Placed[LineLegend @ {"Assignment by lottery", "Complete equality", 
    "FCFS"}, {0.35, 0.7}],
 PlotStyle -> {RGBColor[0.368417, 0.506779, 0.709798], 
   RGBColor[0.560181, 0.691569, 0.194885], 
   RGBColor[0.922526, 0.385626, 0.209179]}, 
 AxesLabel -> {F[t], Subscript[L, P][F[t]]}, 
 LabelStyle -> Directive[{FontColor -> Black}, {FontSize -> 16}], 
 Exclusions -> None]

enter image description here

Use Filling -> {2 -> {3}} to get

enter image description here

$\endgroup$
3
  • $\begingroup$ @kgir Thanks a lot! This is great. There's only one small issue: the legend font appears to be larger in the output of your code. Is there a way to reduce the font of the legend? (but not the font of the axes) $\endgroup$
    – afshi7n
    May 28 '20 at 5:29
  • $\begingroup$ @afshi7n, you can use PlotLegends -> Placed[LineLegend[{"Assignment by lottery", "Complete equality", "FCFS"}, LabelStyle -> 12], {0.35, 0.7}] (or use your desired fontsize in place of 12) $\endgroup$
    – kglr
    May 28 '20 at 5:34
  • $\begingroup$ Thank you so much $\endgroup$
    – afshi7n
    May 28 '20 at 5:44

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.