Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I produce a fill (in a plot) that extends between two given abscissa values, and "infinitely" in the ordinate direction? (Of course, here "infinitely" just means "up to the top and bottom boundaries of the plot, whatever those may be".)

I thought that RegionPlot would do the trick, but no: RegionPlot requires that the extent of regions be fully specified in both directions; e.g. it does not understand a third parameter having a form anything like {y, -Infinity, Infinity}.

EDIT: Let me clarify the question.

Just as an example, imagine that I have a random bunch of Graphics objects displayed together:

enter image description here

OK, now, I want to show a vertical shaded band between x=-1 and x=1. Conceptually, this is a very simple, commonplace idea, but to do it with Mathematica one must suffer a little...

Note that for the desired modification only two parameters are relevant: the abscissas of the edges of the region of interest. Any $y$-dimension information is completely extraneous to the problem, and can only complicate or sharply reduce the generality of the original figure.

I was not able to find any way to do what I want to do that did not require specifying extraneous, irrelevant parameters. For example:

enter image description here

Why did the aspect ratio change? Who knows.

More importantly, notice that for RegionPlot I had to specify the irrelevant range parameters {x, -5, 5} and {y, -1, 6}. These parameters are, in fact, worse than irrelevant: they actually mess up what was there before. For example, now the content-agnostic All spec in the pre-existing PlotRange->{{-5, 5}, All} parameter, and the also content-agnostic PlotRangePadding->0.5 specification, no longer work. I have to replace the first one with a fragile, hard-coded vertical range specification, and fuss with the second one:

enter image description here

My hope is to find a way to achieve the same effect that is less disruptive, and that it does not force me to specify irrelevant or excessively specific parameters.

share|improve this question
1  
Related –  Kuba Sep 8 '13 at 14:26

1 Answer 1

up vote 3 down vote accepted

I propose using Prolog and Rectangle:

Graphics[
  Table[{Hue[t/20], Circle[{Cos[2 Pi t/20], Sin[2 Pi t/20]}]}, {t, 20}], 
  Axes -> True,
  Prolog -> {Opacity[0.2, Cyan], Rectangle[{0.5, -1*^4}, {1.5, 1*^4}]}
]

enter image description here

Unfortunately there is no simple way to Combine absolute and relative (scaled) coordinates so I simply used a "large" value for Y limits.

share|improve this answer
    
Thank you, that's very instructive. Believe it or not, in this answer, the aspect I find most intriguing (both illuminating and baffling at the same time) is your choice "large" values of $y$, because they strike me as surprisingly modest. In one of my many failed attempts to get this to work, I tried the limits [-big, big] with big = Infinity (naively thinking that Mathematica would surely be hip to this), and when that failed, the more pedestrian big = $MaxMachine, which also failed... –  kjo Sep 8 '13 at 15:18
1  
...When I tried such big numbers with your Graphic, the cyan rectangle vanished! In fact, this is the case for any big $> 10^{6.19}$ or so, at least on my hardware, which explains some of my earlier failures (even as it introduces new conundrums, such as why this particular upper limit). Well, at least I've learned that sometimes Mathematica behaves surprisingly parochially in the face of some large numbers! Thanks again! –  kjo Sep 8 '13 at 15:18
    
@kjo Your right; at first I tried larger values myself but the blue rectangle became invisible when I resized the graphic. I'm afraid Mathematica is ignoring values that are too far out of the specified plot range, or perhaps are too great in magnitude relative to other values. This is worth exploration but I don't have time right now. It would be far better if we could used mixed Scaled coordinates but sadly at this time we cannot. –  Mr.Wizard Sep 8 '13 at 15:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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