Add a rectangle to a plot to indicate range

In summary, the conversation discusses how to add a rectangular region to cover a specific range behind a plot of a linear function. It also mentions using a dashed line to indicate the maximum y-value and importing data points from excel. The suggested solution involves using the Show function with Plot and Graphics, and using EdgeForm to adjust the appearance of the rectangle. It is also possible to fill the rectangle with a desired color. For adding a dashed line as the upper boundary, the Epilog function can be used.
  • #1
Whitehole
132
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.
 
Physics news on Phys.org
  • #2
Try something like
Code:
Show[Plot[x, {x, 0, 10}],
Graphics[{EdgeForm[Thin], Transparent, Rectangle[{4, 0}, {7, 10}]}]]
plot.jpg
 
  • #3
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?
 
  • #4
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.
 
  • #5
DrClaude said:
Yes, simply replace Transparent by the desired color.
How should I use Epilog for the dashed line upper boundary?
 
  • #6
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?
 

1. What is the purpose of adding a rectangle to a plot to indicate range?

Adding a rectangle to a plot to indicate range is a useful way to visually represent the range of data in a plot. It can help viewers quickly understand the spread of the data and identify any outliers or patterns.

2. How do you add a rectangle to a plot to indicate range?

To add a rectangle to a plot, you can use the "rect" function in your plotting software. You will need to specify the coordinates of the rectangle as well as the color and other visual properties.

3. Can you add multiple rectangles to a plot to indicate different ranges?

Yes, you can add multiple rectangles to a plot to indicate different ranges. This can be done by using the "rect" function multiple times, each with different coordinates and visual properties.

4. Is it possible to customize the appearance of the rectangle added to a plot?

Yes, you can customize the appearance of the rectangle added to a plot. This includes changing the color, border style, and transparency, among other visual properties.

5. Are there any alternative ways to indicate range on a plot besides using a rectangle?

Yes, there are alternative ways to indicate range on a plot. These include using error bars, shading, or highlighting specific data points. The choice of method will depend on the type of data and the message you want to convey to the viewer.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
847
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • Precalculus Mathematics Homework Help
Replies
23
Views
611
  • Precalculus Mathematics Homework Help
Replies
15
Views
648
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
768
Back
Top