Add a rectangle to a plot to indicate range

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
5 replies · 5K views
Whitehole
Messages
128
Reaction score
4
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.
 
on Phys.org
Try something like
Code:
Show[Plot[x, {x, 0, 10}],
Graphics[{EdgeForm[Thin], Transparent, Rectangle[{4, 0}, {7, 10}]}]]
plot.jpg
 
DrClaude said:
Try something like
Code:
Show[Plot[x, {x, 0, 10}],
Graphics[{EdgeForm[Thin], Transparent, Rectangle[{4, 0}, {7, 10}]}]]
View attachment 205513
Is it possible for the rectangle to be filled,say by light blue color or light green?
 
Whitehole said:
Is it possible for the rectangle to be filled,say by light blue color or light green?
Yes, simply replace Transparent by the desired color.
 
DrClaude said:
Yes, simply replace Transparent by the desired color.
How should I use Epilog for the dashed line upper boundary?
 
Whitehole said:
How should I use Epilog for the dashed line upper boundary?
I don't understand what you have in mind. Could you make a sketch?