I'm plotting my data points and I want to compare it to the experimentally accepted values. How can I apply the graphics option as shown below, I want to add a rectangular region to indicate the bound on the accepted values.Image

ListLogLinearPlot[data2, AxesLabel -> {Subscript[n, s], r}, LabelStyle -> {Black, 13},
PlotStyle -> Red, PlotRange -> {{0.94, 1}, Full}, PlotMarkers -> {Automatic, Medium},
Prolog -> {LightBlue, Rectangle[{0.94, 0}, {0.97, 0.11}]}, Epilog -> {Thick, Black, Dashed, Line[{{0.94, 0.11}, {1, 0.11}}]}]

Generally you can use the Prolog option and standard Graphics primitives like Rectangle (example) but for the given style you can use Filling directives in Plot itself, like this:

  {5, 8, 2 Sin[x] + x, x - 5 Sinc[x]}, {x, 0, 15}, 
  PlotStyle -> Join[{None, None}, ColorData[97, "ColorList"]], 
  Filling -> {1 -> {15, LightBlue}, {2 -> {12, Yellow}}}

enter image description here

The Filling method can be a little harder to set up but it scales well when changing PlotRange etc.

| improve this answer | |
  • $\begingroup$ I have added the code that I have written but it's not working. I have also added a dashed line to indicate the bound on the y-axis, the shaded region that I want is a bound on the x-axis. The image that I have shown is just an example of what I want to achieve (colored region). $\endgroup$ – mathemania Jun 6 '17 at 6:51
  • $\begingroup$ @mathemania If you are using a ListPlot variation the Filling method won't work directly, so I suggest you use Prolog. Without a copy of your data2 I can't evaluate your plot; perhaps you would include a minimal example? $\endgroup$ – Mr.Wizard Jun 6 '17 at 6:59
  • $\begingroup$ I have used Prolog, not Filling. Also, Epilog doesn't work. $\endgroup$ – mathemania Jun 6 '17 at 7:07
  • $\begingroup$ @mathemania Yes I see, but I don't want to have to craft dummy data just to run your code; please do that yourself. $\endgroup$ – Mr.Wizard Jun 6 '17 at 7:08
  • $\begingroup$ My data points are in an excel file, maybe a linear function with 3 points would be enough just to show an example, maybe the domain is x=1,2,3 and the values are y=1,2,3 for a linear function y=x. $\endgroup$ – mathemania Jun 6 '17 at 15:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.