3
$\begingroup$

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.

$\endgroup$

closed as off-topic by bbgodfrey, ubpdqn, Feyre, Bob Hanlon, Young Aug 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.

4
$\begingroup$

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}}]

enter image description here

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.

$\endgroup$
  • $\begingroup$ @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. :) $\endgroup$ – ubpdqn Aug 24 '16 at 6:59
6
$\begingroup$
RegionPlot[ImplicitRegion[x == 1, {x, y}]]
$\endgroup$
5
$\begingroup$

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"]

enter image description here

$\endgroup$
4
$\begingroup$

RegionPLotexpects an inequality; you are specifying an equality.

I suggest you use ParametricPlotas below:

ParametricPlot[{1, y}, {x, 0, 2}, {y, 0, 2}]

enter image description here

$\endgroup$
3
$\begingroup$

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]}]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.