4
$\begingroup$

I have a multivalued curve p1 (left curve) and a normal curve xpr2 (right), and I want to fill the middle region between them as blue, and the rightmost region as red.

However, I get this extra filled part above my multivalued function, presumably because the xpr2 curve is above that part. Is there a way to get the plot to ignore filling beyond a certain point?

xpr1[y_] := 5.077959119860908` - 15.96152127464673` y^(1/3) + 11.632042032912723` Sqrt[y];
xpr2[x_] := 2.4673477623994344` - 1.8055789567179195` x + 0.5471986643936791` x^2 - 0.055509819604498495` x^3;
p1[y_] := {xpr1[y], y};
Plot[{xpr2[x], p1[y][[2]] /. NSolve[p1[y][[1]] == x]}, {x, 0, 2},
  PlotRange -> {{0, 2}, {0.2, 1.2}}, 
 Filling -> {1 -> {{2}, {Red, Blue}}}]

Result:

enter image description here

And this is what I want it to look like:

enter image description here

$\endgroup$
1
  • $\begingroup$ Your function curves back on itself and filling in Plot is filling until it reaches the second plot. The filling meets the second plot outside of the plot range. You may have to use ParametricPlot or something like that. $\endgroup$
    – Edmund
    Nov 10, 2015 at 17:50

3 Answers 3

5
$\begingroup$

You can draw branches separately and choose the right filling

p1[y_] := {xpr1[y], y};
Plot[{p1[y][[2]] /. NSolve[p1[y][[1]] == x][[1]], 
  p1[y][[2]] /. NSolve[p1[y][[1]] == x][[2]], xpr2[x]}, {x, 0, 2}, PlotRange -> All,
  Filling -> {3 -> {{1}, {Red, None}}, 1 -> {{2}, Blue}}, 
 PlotStyle -> {ColorData[97, 1], ColorData[97, 1], ColorData[97, 2]}]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ It is quite strange to see the filling artifacts (white pixels) under the top (blue) curve on your plot. I don't get these with version 10.3 on Win7 x64. What is you OS/version? $\endgroup$ Nov 10, 2015 at 20:52
  • 1
    $\begingroup$ @AlexeyPopkov version 10.3 on Linux $\endgroup$
    – ybeltukov
    Nov 10, 2015 at 21:14
4
$\begingroup$
Show[{
  RegionPlot[ y < xpr2[x] && x > xpr1[y] , {x, 0, 3}, {y, 0, 3}, 
   PlotStyle -> Blue],
  RegionPlot[ y > xpr2[x] && x > xpr1[y] , {x, 0, 3}, {y, 0, 3}, 
   PlotStyle -> Red],
  Plot[xpr2[x], {x, 0, 3}, PlotStyle -> Green],
  ParametricPlot[{xpr1[y], y}, {y, 0, 3}, PlotStyle -> Black]
  }, PlotRange -> {{0, 2}, {0, 3}}]

enter image description here

$\endgroup$
3
$\begingroup$

If you don't clip the plot with PlotRange, you will see that the filling is exactly as you asked for it to be.

Plot[{xpr2[x], p1[y][[2]] /. NSolve[p1[y][[1]] == x]}, {x, 0, 2}, 
  Filling -> {1 -> {{2}, {Red, Blue}}}]

plot

$\endgroup$
2
  • $\begingroup$ See my edit please. $\endgroup$
    – induvidyul
    Nov 10, 2015 at 19:10
  • $\begingroup$ +1 Because I understood the same thing from the original post $\endgroup$ Nov 10, 2015 at 19:22

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.