Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Add a rectangle to a plot to indicate range

  1. Jun 15, 2017 #1
    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. jcsd
  3. Jun 16, 2017 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Try something like
    Code (Text):
    Show[Plot[x, {x, 0, 10}],
    Graphics[{EdgeForm[Thin], Transparent, Rectangle[{4, 0}, {7, 10}]}]]
    plot.jpg
     
  4. Jun 16, 2017 #3
    Is it possible for the rectangle to be filled,say by light blue color or light green?
     
  5. Jun 16, 2017 #4

    DrClaude

    User Avatar

    Staff: Mentor

    Yes, simply replace Transparent by the desired color.
     
  6. Jun 18, 2017 #5
    How should I use Epilog for the dashed line upper boundary?
     
  7. Jun 19, 2017 #6

    DrClaude

    User Avatar

    Staff: Mentor

    I don't understand what you have in mind. Could you make a sketch?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted