# Mathematica Add a rectangle to a plot to indicate range

Tags:
1. Jun 15, 2017

### Whitehole

I have some data points that I want to plot and suppose I have the function $f(x) = x$, with the domain having the range $0\leq x \leq 10$. Assume that the experimental values lies in the range $4\leq x \leq 7$, how can I put a rectangular region to cover this range behind my plot so as to show that range? The y-range should not be a trouble here since I plan to use a different option for that, so the rectangular region should just show the bound for the x-range.

For the y-range suppose the maximum value for y is 8, how can I put a dashed line to indicate the maximum y-value?

I have tried to use the epilog and prolog but they don't work, I mean just based on what I saw from some posts, but I'm really a newbie on this so it's not even worth a look. Maybe somebody can give me a basic example or guide?

Also, my data points are imported from excel, but let's just assume that the data points can be represented by the linear function above to make things simple; x,y values take on discrete values.

2. Jun 16, 2017

### Staff: Mentor

Try something like
Code (Text):
Show[Plot[x, {x, 0, 10}],
Graphics[{EdgeForm[Thin], Transparent, Rectangle[{4, 0}, {7, 10}]}]]

3. Jun 16, 2017

### Whitehole

Is it possible for the rectangle to be filled,say by light blue color or light green?

4. Jun 16, 2017

### Staff: Mentor

Yes, simply replace Transparent by the desired color.

5. Jun 18, 2017

### Whitehole

How should I use Epilog for the dashed line upper boundary?

6. Jun 19, 2017

### Staff: Mentor

I don't understand what you have in mind. Could you make a sketch?