5
$\begingroup$

This question already has an answer here:

I would like to make a filling of a plot between two curved dynamically.I have two lines depending upon parameters. They may cross one another, and may not in different domains of the parametric space. I would like to plot them and make filling between these lines, but only if the line 2 lies above the line one, and not otherwise. To be specific, consider a simplistic example:

 k = -0.5;
Plot[{0.5*x^2, x^2 + k}, {x, -2, 2}, Filling -> {1 -> {2}}]

here k is parameter. This yields the expected plot where the area between the two curves is filled everywhere. I need, however, that it would be filled only at x>1 and x<-1. Further I would like to wrap all this with Manipulate statement varying k to have all in dynamics. In addition the real problem that I have is rather complex. These two curves can have none or multiple intersection points depending upon parameters. Thus, the idea to divide the curves into parts between points does not help. This:

    k = -0.5;
Plot[{0.5*x^2, x^2 + k}, {x, -2, 2}, 
 Filling -> If[0.5*x^2 < x^2 + k, {1 -> {2}}]]

makes no filling. Any other ideas?

$\endgroup$

marked as duplicate by m_goldberg, Öskå, Simon Woods, Mr.Wizard Sep 7 '14 at 12:48

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.

  • $\begingroup$ Filling -> {1 -> {{2}, {Automatic, None}}} ? $\endgroup$ – Simon Woods Sep 7 '14 at 10:43
  • $\begingroup$ I agree that there is no practical difference between my question and the one pointed out above $\endgroup$ – Alexei Boulbitch Sep 8 '14 at 8:30
6
$\begingroup$

You can use a specification in the following format (explained under Details in Filling):

ik -> {pk, {gk-, gk+}}

Then

Plot[{0.5*x^2, x^2 + k}, {x,-2,2}, Filling -> {1 -> {{2}, {None, Red}}}]

Plot

This also works as desired with Manipulate, e.g.

Manipulate[
 Plot[{0.5*x^2, x^2 + k}, {x, -2, 2}, Filling -> {1 -> {{2}, {None, Red}}}],
 {k, -1, 1}]

Plot1 Plot2

$\endgroup$

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