Message Boards Message Boards

0
|
2097 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Filling between plots for a specified interval

Posted 11 months ago

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

Attachment

POSTED BY: Geoffrey Marnell
3 Replies

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}}]]
POSTED BY: Gianluca Gorni
Posted 11 months ago

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}}}]
POSTED BY: Hans Milton

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.

POSTED BY: Gareth Russell
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract