Add a rectangle to a plot to indicate range

Click For Summary

Discussion Overview

The discussion revolves around how to visually represent a specific range on a plot using rectangles and dashed lines in a plotting software. Participants are exploring methods to indicate a range of x-values and a maximum y-value on a graph, with a focus on graphical representation techniques.

Discussion Character

  • Exploratory, Technical explanation, Homework-related

Main Points Raised

  • One participant describes their intention to plot a function and highlight a specific range of x-values using a rectangle, while also indicating a maximum y-value with a dashed line.
  • Another participant suggests a code snippet to create a rectangle covering the specified x-range, indicating the use of the Plot and Graphics functions.
  • A follow-up question asks if the rectangle can be filled with color, such as light blue or light green.
  • Participants confirm that the rectangle can be filled by replacing the Transparent option with a color.
  • There is a request for guidance on using Epilog to create a dashed line for the upper boundary of the plot.
  • A participant expresses confusion regarding the dashed line implementation and requests a sketch for clarification.

Areas of Agreement / Disagreement

Participants generally agree on the methods to create a rectangle and fill it with color, but there is uncertainty regarding the implementation of the dashed line and a lack of consensus on how to clarify that aspect.

Contextual Notes

Some participants are new to the plotting software, which may affect their understanding and ability to implement the suggested solutions. There are also unresolved questions about the specifics of using Epilog for dashed lines.

Who May Find This Useful

Individuals interested in data visualization, particularly those using plotting software to represent ranges and boundaries in their graphs, may find this discussion beneficial.

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.
 
Physics news 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?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K