This question already has an answer here:

Suppose I have plotted two functions $f(x)$ and $g(x)$ on the same plot. I would like to shade the area between the two curves only when $f(x) \geq g(x)$, but I cannot get the Filling command to do the job. Here is my code:

f[n_, d_] := (Sin[Pi/n] + (Sin[Pi/n]^2 + 4*n^2*d^2)^(1/2))/(2*n);R[n_, d_] := 1 - (d^2 + Cos[Pi/n]^2)^(1/2);Plot[{f[4, d], R[4, d]}, {d, 0, 0.2}, AxesLabel -> {d},  PlotLegends -> "Expressions",  Filling -> {1 -> {2}, R[4, d] > f[4, d]}]

The graph produces the shaded region everywhere between $f(4,d)$ and $R(4,d)$, but I only want the region between the two curves when $R(4,d) \geq f(4,d)$, or in other words, up untill $d \simeq 0.16$.

Any help would be appreciated!


marked as duplicate by bbgodfrey, Edmund, Mr.Wizard plotting Jul 27 '16 at 1:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    $\begingroup$ Check the documentation of Filling please. That already explained everything. $\endgroup$ – Wjx Jul 27 '16 at 0:13
  • $\begingroup$ I believe you want e.g. Filling -> {1 -> {{2}, {Red, None}}} $\endgroup$ – Mr.Wizard Jul 27 '16 at 1:16
  • $\begingroup$ @Alex You're welcome. A couple of notes: (1) If ever your question is marked as a duplicate but you still cannot find a solution to your problem you can edit the question to explain how your needs differ, and it will automatically be added to the Reopen Review Queue. (2) You may find value in reading the Related questions linked in the sidebar to the right, or browsing the filling tag directly. $\endgroup$ – Mr.Wizard Jul 27 '16 at 16:16

Browse other questions tagged or ask your own question.