Hi
I have plotted y = x^2 and y = 2x + 3 on the one graph and want to fill just the space between the plots for a specified interval. None of the filling examples in the Wolfram documentation seem to cover this. I have attached the plot and you can see that, for the domain I’ve specified and the option “Filling → {1 → {2}”, there are three filled segments. I only want the second segment filled (between x = -1 and x = 3). Is this possible with Mathematica?
TIA
Geoffrey
Not very elegant, but you can combine two or three plots:
Show[Plot[{x^2, 2 x + 3}, {x, -3, 4}],
Plot[{x^2, 2 x + 3}, {x, -1, 3}, Filling -> {1 -> {2}}]]
The following does not specify an interval, but separates the fillings between the areas above and below the first curve:
Plot[{x^2,2 x+3},{x,-3,4},Filling->{1->{{2},{Automatic,None}}}]
For even more control, use a custom ColorFunction in the ‘bottom’ plot that has the filling:
Show[Plot[{x^2, 2 x + 3}, {x, -3, 4}, Filling -> {1 -> {2}},
ColorFunction ->
Function[{x, y},
If[-1 < x < 3, RGBColor[0.817029, 0.811551, 0.899535],
RGBColor[1, 1, 1]]], ColorFunctionScaling -> False],
Plot[{x^2, 2 x + 3}, {x, -3, 4}]]
By changing the parameters if the If statement, you can make the filling be exactly where you want it.
