# What is the equation to plot a vertical line?

Please help. Trying to find area between three curves, e^-x, x = 2, y = 1. Can't find out how to plot x = 2. Don't want to use Epilogue unless it can shade the area enclosed by the three curves.

• stackoverflow.com/questions/2897277/… – Igor Rivin Sep 12 '14 at 1:15
• gridlines and epilog are the answers to that question - if I'm not mistaken both are done after the initial graphics rendering, meaning that the filling command will continue shading past the point the lines are drawn. I need a solution that will allow me to actually plot the equation x = 2 – Cory Sep 12 '14 at 1:19
• A related question is Calling Correct Function for Plotting DiracDelta. Not the same because the plot has value 0 away from the spike. – Jens Sep 12 '14 at 5:50
• Couldn't you use the HeavisideTheta function? Just multiply HeavisideTheta(x-2) by something that is infinite fpr the purposes of your application (i.e. bigger than your visible y-max). One such number could be 100. – Christofer Ohlsson Sep 12 '14 at 8:08

you can also try:

PolarPlot[2/Cos[t], {t, 0, Pi/4}]


or

ContourPlot[x == 2, {x, 0, 4 Pi}, {y, 0, 4 Pi}]


If you want to find the area using other method, I would suggest to use Area and ImplicitRegion in V10 as follows:

r = ImplicitRegion[y >= Exp[-x] && x <= 2 && y <= 1, {x, y}];
Area[r]

(*(1 + E^2)/E^2*)


for shading issue you may find this interesting:

Show[{ContourPlot[{x == 2, y == Exp[-x], y == 1}, {x, -1, 3}, {y, 0,
2}], RegionPlot[r, ColorFunction -> "Rainbow"]}]      (*@ Rahul Narain*)


or

Show[{Plot[{Exp[-x], 1}, {x, -2, 3}],
PolarPlot[2/Cos[t], {t, 0, 2 \[Pi]}],
RegionPlot[r, ColorFunction -> "Rainbow"]}] • Used the advice above. Thank you. – Cory Sep 12 '14 at 2:24
• You could combine both the Plot and the PolarPlot into a single ContourPlot in your last example. In any case I feel the PolarPlot form is a little opaque while ContourPlot[x == 2, ...] is perfectly clear. – user484 Sep 12 '14 at 2:50
• @RahulNarain, thanks for the advice. in polar, you know x=rCos[t] or r=x/Cos[t], for this case x=2 and r=2/Cos[t]. – Basheer Algohi Sep 12 '14 at 2:57

Its my understanding that you want to insist on using Plot for this problem. Then how about defining a function that has a vertical jump at x=2 and otherwise exceeds the required PlotRange so that its remaining parts won't show up?

Plot[100 Sign[x - 2], {x, -3, 3}, ExclusionsStyle -> Red,
PlotRange -> {-1, 1}] • I was about to suggest \$MaxMachineNumber might be a good choice for the coefficient 100, but apparently not. (+1) – Michael E2 Sep 12 '14 at 2:17
• This works well enough. I'm really surprised there is no plain way to plot a vertical line. Thank you. – Cory Sep 12 '14 at 2:23
• Plot[9!(x-2),{x,-3,3},PlotRange->{-3,3}] – matrix89 Sep 12 '14 at 16:23

The new V10 region functionality is rather suited to implementing your description of the problem in a direct way:

reg = ImplicitRegion[y < 1 && y > E^-x && x < 2, {x, y}];
Show[BoundaryDiscretizeRegion[reg, {{0, 2}, {E^-2, 1}}], Axes -> True,
AxesOrigin -> {0, 0}, AspectRatio -> 1/GoldenRatio] Also for finding the area:

RegionMeasure[reg]
(* (1 + E^2)/E^2 *)

• There are, except that the OP has pooh-poohed all of them before. – Igor Rivin Sep 12 '14 at 3:19
Show[
RegionPlot[y > E^-x && y < 1 && x < 2,
{x, -1, 3}, {y, 0, 1.5}],
Plot[{
{x, -1, 3}],
Epilog -> Tooltip[Line[{{2, 0}, {2, 1.5}}], area = Integrate[1 - E^-x, {x, 0, 2}]


1 + 1/E^2

You might find the answers to an old question on StackOverflow useful

My suggested hack in that case involved Rotate:

ticks = {{None, ({#, Rotate[#, 90 Degree], {0.02, 0}} & /@
Range[0, 4])}, {({#, Rotate[#, 90 Degree], {0.02, 0}} & /@
Range[0, 1, 0.25]), None}};

Rotate[Plot[2, {x, 0, 1}, AspectRatio -> GoldenRatio,
AxesOrigin -> {1, 0}, Frame -> True,
FrameTicks -> ticks], -90 Degree] Of course, since you want to plot x=something and y=something simultaneously, this might not work for you, in which case I'd recommend Jens' answer, or hacking the setting for AxesOrigin to create a horizontal line as well as a vertical one.

ParametricPlot[{10, y}, {x, -10, 10}, {y, -10, 10}] works for me.

• Is there any way to actually plot the equation x = 2, with the Plot function? ParametricPlot is still not what I'm looking for. I'm trying to enclose an area. – Cory Sep 12 '14 at 1:30
• No, there is not. – Igor Rivin Sep 12 '14 at 1:48

First we construct some helpers:

f[x_] := E^(-x)

yval = f


1/E^2

h[x_] := 1

v[t_] := 2


Vertical lines can be constructed with ParametricPlot:

ParametricPlot[{v[t], t}
, {t, yval, 1.}
, PlotStyle -> {Darker[Red], Thick}
, PlotRange -> {{-.5, 2.5}, {0, 1.5}}] Putting it all Together:

Show[Plot[{f[x], h[x]}
, {x, 0., 2.}
, Filling -> {2 -> {1}}]
, ParametricPlot[{v[t], t}
, {t, yval, 1.}
, PlotStyle -> {Darker[Red], Thick}]
, PlotRange -> {{-.5, 2.5}, {0, 1.5}}] Edit

You can also work with Epilog, Line or Arrow

Plot[{f[x], h[x]}
, {x, 0, 2}
, PlotRange -> {{-.5, 2.5}, {0, 1.5}}
, Epilog -> {Thick, Darker[Red], Line[{{2, yval}, {2, 1}}]}
, Filling -> {2 -> {1}}
, Frame -> True
, Axes -> False
] Plot[{f[x], h[x]}
, {x, 0, 2}
, PlotRange -> {{-.5, 2.5}, {0, 1.5}}
, Epilog -> {Thick, Darker[Red], Arrow[{{2, yval}, {2, 1}}]}
, Filling -> {2 -> {1}}
, Frame -> True
, Axes -> False
]    Thx @Jens and @Bob Hanlon for inspiration.