Re: Plot and filling option
- To: mathgroup at smc.vnet.net
- Subject: [mg94592] Re: Plot and filling option
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Wed, 17 Dec 2008 06:32:26 -0500 (EST)
- Organization: The Open University, Milton Keynes, UK
- References: <gi821v$gdr$1@smc.vnet.net>
Pat wrote:
> I need some help to make a nice plot for my teaching.
>
> I'd like to graph the following interval:
> 0 < x < 1
> 0 < y < 3
> 0 < x y < 2.
>
> I did this:
>
> Plot[{3, 2/x}, {x, 0, 4}, AxesLabel -> {"x", "y"},
> Prolog -> {Line[{{1, 0}, {1, 4}}]}, Filling -> {1 -> Top, 2 -> Top},
> PlotRange -> {0, 4}]
>
> But I have no idea how I can fill the right side of the vertical line
> X=1.
>
> If you have any suggestions. Maybe I should write another code.
Two things come up to my mind. One can add a second plot that fills the
missing region (first example below) or on can use a polygon to build
and fill the desired region (second example below).
p1 = Plot[{3, 2/x}, {x, 0, 4}, AxesLabel -> {"x", "y"},
Prolog -> {Line[{{1, 0}, {1, 4}}]},
Filling -> {1 -> Top, 2 -> Top}, PlotRange -> {0, 4}];
p2 = Plot[3, {x, 0, 1}, Filling -> {1 -> Bottom}];
Show[p1, p2]
poly = Polygon[{{0, 0}, {1, 0}, {1, 3}, {4, 3}, {4, 4}, {0, 4}}];
reg = Graphics[{Directive[Opacity[.2]], poly}];
p = Plot[2/x, {x, 0, 4}, AxesLabel -> {"x", "y"},
Filling -> {1 -> Top},
FillingStyle -> Directive[Opacity[.4], Orange],
PlotRange -> {0, 4}];
Show[p, reg]
Regards,
-- Jean-Marc