# How to draw a line using RegionPlot? [closed]

I want to draw a vertical line x=1 with legend "x=1" using RegionPlot. I type the following code in Mathematica 11:

RegionPlot[x == 1, {x, 0, 2}, {y, 0, 2}, PlotLegends -> "x=1"]


However, the output does not contain the line x=1. What should I do to obtain the correct output? Thank you very much in advance.

## closed as off-topic by bbgodfrey, ubpdqn, Feyre, Bob Hanlon, YoungAug 24 '16 at 13:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bbgodfrey, ubpdqn, Feyre, Bob Hanlon, Young
If this question can be reworded to fit the rules in the help center, please edit the question.

• – JungHwan Min Aug 24 '16 at 3:50
• @JHM Thank you for your comment. – Wei-Cheng Liu Aug 24 '16 at 6:51

## 5 Answers

There are many ways to do this, e.g.

Plot[{}, {x, 0, 2}, GridLines -> {{1}, None},PlotRange -> {{0, 2}, {0, 2}}]
ContourPlot[x == 1, {x, 0, 2}, {y, 0, 2}]
ParametricPlot[{1, u}, {u, 0, 2}, PlotRange -> {{0, 2}, {0, 2}}] You could "do" with RegionPlot:

RegionPlot[x < 1, {x, 0, 2}, {y, 0, 100},
PlotStyle -> White, PlotRange -> {{0, 2}, {0, 2}}]


However, ContourPlotis probably what is wanted.

• @Wei-ChengLiu I am glad it was helpful. The flexibility in Mma is one of its useful and fun features. Play (testing what different functions do) has been very instructive to me. :) – ubpdqn Aug 24 '16 at 6:59
RegionPlot[ImplicitRegion[x == 1, {x, y}]]


As stated in the documentation, RegionPlot only plots 2D regions.

ContourPlot is the function you're looking for.

ContourPlot[x == 1, {x, 0, 2}, {y, 0, 2}, PlotLegends -> "x=1"] RegionPLotexpects an inequality; you are specifying an equality.

I suggest you use ParametricPlotas below:

ParametricPlot[{1, y}, {x, 0, 2}, {y, 0, 2}] If you really want to do this with RegionPlot as you may wish to overlay a region with a line x=1, use Epilog to add a graphic (in this case a Line).

line = Table[{1, y}, {y, 0, 2}];

RegionPlot[x^2 + y^2 < 1, {x, 0, 2}, {y, 0, 2}
, PlotLegends -> "x=1"
, Epilog -> {Red, Line[line]}] 