I'd like to fill a plot down to the x-axis but restrict the fill to lie between two x values, and am not sure how to do it. For example, if I plot a parabola f[x] = x^2, with x in the range =E2=88=9210 to 10, I'd like to be able to fill to the x-axis between x = 2 and x = 7, essentially creating a filled column. Is there any way to do that?
Regards,
Gregory
Plot[{x^2, If[2 <= x <= 7, 0]}, {x, 0, 10},
PlotStyle -> {Automatic, None}, Filling -> {1 -> {2}}]
I think you have to make two plots and combine them with Show:
pl1 = Plot[x^2, {x, -5, 10}];
pl2 = Plot[x^2, {x, 2, 7}, Filling -> Axis];
Show[pl1, pl2]
Beware: The order of the plots in Show is critical, if you swap it, Show
will disply pl2 only, because it uses the options of the first plot given.
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
Plot[{x^2, Piecewise[{{x^2, 2 < x < 7}}]}, {x, -5 , 10},
Filling -> {2 -> Axis}]
Bob Hanlon
---- Gregory Lypny <gregor...@videotron.ca> wrote:
=============
Gregory
On Wed, Mar 30, 2011, at 8:04 AM, Chris Degnen wrote:
> On Mar 30, 10:18 am, Gregory Lypny <gregory.ly...@videotron.ca> wrote:
p1 = Plot[x^2, {x, 2, 7}, Filling -> Axis, PlotRange -> {{0, 10}, {0, 100}}];
p2 = Plot[x^2, {x, 0, 10}, PlotRange -> {{0, 10}, {0, 100}}];
Show[p1,p2]
David
Another good solution. I also didn't know that we could mess around with antialiasing.
Regards,
Gregory
On Wed, Mar 30, 2011, at 9:17 AM, David Park wrote:
> Gregory,
>
> Here is your graphic in regular Mathematica using the Show statement. I've
> embellished it slightly by adding vertical lines on the filled region - just
> to show how you might do things like that.
>
> f[x_] := x^2
> Show[
> {Plot[f[x], {x, 2, 7}, Filling -> Axis,
> FillingStyle -> Lighter@Orange, PlotStyle -> None],
> Plot[f[x], {x, 0, 10}],
> Graphics[
> Style[{Line[{{2, 0}, {2, f[2]}}], Line[{{7, 0}, {7, f[7]}}]},
> Antialiasing -> False]]},
> AspectRatio -> 1,
> AxesOrigin -> {0, 0},
> PlotRange -> All]
>
> 1) It is necessary to use PlotRange->All, otherwise it is picked up from the
> first Plot.
> 2) We draw the filled region first with PlotStyle->None so that the second
> Plot won't overlay a line that might not exactly register with the first
> line (because the two plots won't use the same points).
> 3) We have to enclose the vertical lines in a Graphics statement to get them
> on the same graphics level as the Plot statements.
> 4) Style with Antialiasing->False was used so the vertical lines will both
> be sharp, otherwise the automatic Antialiasing might produce some fuzziness.
> This is useful for horizontal or vertical lines.
>
> Here is the same graphic using the Presentations package. It is a little
> more intuitive since everything is at the graphics primitive level and there
> is a simpler Aliasing command. You just draw one thing after another.
>
> << Presentations`
>
> f[x_] := x^2
> Draw2D[
> {Draw[f[x], {x, 2, 7}, Filling -> Axis,
> FillingStyle -> Lighter@Orange, PlotStyle -> None],
> Draw[f[x], {x, 0, 10}],
> Aliasing@{Line[{{2, 0}, {2, f[2]}}], Line[{{7, 0}, {7, f[7]}}]}},
> AspectRatio -> 1,
> Axes -> True]
>
>
> David Park
> djm...@comcast.net
> http://home.comcast.net/~djmpark/
>
>
>
> From: Gregory Lypny [mailto:gregor...@videotron.ca]
>
>
> Hello everyone,
>
> I'd like to fill a plot down to the x-axis but restrict the fill to lie
> between two x values, and am not sure how to do it. For example, if I plot
> a parabola f[x] = x^2, with x in the range ==E2==88==9210 to 10, I'd like to be