I can hack it using "y" = very big number times "x" but is there a
more elegant way to do it?
The best ways to plot vertical lines on your plots don't involve
functions of "x", or the Plot command; for example, we can use the
Epilog command on Plot to give us a vertical line drawn between some
pair of points:
Plot[f[x],{x,xmin,xmax}, Epilog->Line[{xval,ymin},{xval,ymax}]]
will plot f from xmin to xmax, and have a vertical line at xval (so
long as xval is in (xmin,xmax)) and you should also take care to see
that ymin and ymax fall within your plot area.
We could also use ParametricPlot:
ParametricPlot[{{xval,u},{u,f[u]}}, {u,umin,umax}]
should give a vertical line at some position "xval," and plot "f"
along the x axis. The documentation center is your friend here; I may
have written these down slightly incorrectly, but experimentation and
documentation should clear that up for you.
-Max
A vertical line is not a function, so Plot won't plot it. You can use
ContourPlot or ParametricPlot to plot a vertical line, or use the
Graphics primitive Line. For example, each of the following will plot
the line x=3.
ContourPlot[x == 3, {x, -5, 5}, {y, -5, 5}]
ParametricPlot[{3, t}, {t, -5, 5}, PlotRange -> 5]
Graphics[Line[{{3, -5}, {3, 5}}], PlotRange -> 5, Axes -> True]
Use Show to combine any of the above with other plots. For instance:
For instance:
plot1 = Plot[x^2, {x, -5, 5}];
plot2 = ParametricPlot[{3, t}, {t, -5, 16}, PlotStyle -> Red];
Show[{plot1, plot2}, PlotRange -> Automatic]
Or use Epilog to add Graphics primitives to a plot. For instance:
Plot[x^2, {x, -5, 5}, Epilog -> {Red, Line[{{3, -5}, {3, 16}}]},
PlotRange -> {-5, 25}]
--
Helen Read
University of Vermont
Plot[Sin[x], {x, 0, 1}, Epilog -> Line[{{.5, 0}, {.5, 1}}]]
creates a vertical line.
ADL
here is an example for a plot with red, dashed, vertical lines:
Plot[x^2, {x, -2, 2}, Epilog -> {Red, Dashed, Line[{{-1, -10}, {-1,
10}}], Line[{{1, -10}, {1, 10}}]}]
Best regards,
Hannes Kessler
I think more specification would help.
But to create a line in Mathematica do help on the Line[] function.
--Nasser
Daniel
Why don't you use Graphics directly?
Graphics[Line[{{1, 0}, {1, 1}}], Axes -> True]
You didn't say what you need that vertical line for. Perhaps
Mathematica already has built-in functionality for what you want. Look
up Exclusions and GridLines.
f[x_] := (x - 1) (x - 2) (x - 3)
mm = x /. Solve[f'[x] == 0, x];
Plot[f[x], {x, 3/4, 13/4},
Epilog -> {Red,
AbsoluteDashing[{5, 5}],
Line[{{#, 0}, {#, f[#]}}] & /@ mm}]
Bob Hanlon
---- davef <davidfr...@yahoo.com> wrote:
=============
How can I create a vertical line using the Plot command?
I can hack it using "y" = very big number times "x" but is there a
more elegant way to do it?
--
Bob Hanlon
>How can I create a vertical line using the Plot command?
>I can hack it using "y" = very big number times "x" but is there a
>more elegant way to do it?
Here are two ways:
Plot[x, {x, 0, 1}, GridLines -> {{.5}, None}]
Plot[x, {x, 0, 1}, Epilog -> {Line@{{.5, -.1}, {.5, 1.1}}}]
>
> How can I create a vertical line using the Plot command?
>
> I can hack it using "y" = very big number times "x" but is
> there a more elegant way to do it?
Don't know about more elegant, but I typically do Line[{{xcoord, smallnum},
{xcoord, bignum}}] and use it in Epilog.
D.
ParametricPlot[{1, y}, {y, 0, 1}]
Or use the Line graphics primitive.
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
Plot[Sin[x],{x,0,2}, Epilog->Line[{{1,0},{1,10}}]]
- Tomas
> Date: Sat, 24 Oct 2009 02:41:18 -0400
> From: davidfr...@yahoo.com
> Subject: How create vertical line using Plot?
> To: math...@smc.vnet.net
>
> How can I create a vertical line using the Plot command?
>
> I can hack it using "y" = very big number times "x" but is there a
> more elegant way to do it?
>
=