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$
5
$\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.

|improve this answer|||||
$\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}]]
|improve this answer|||||
$\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

|improve this answer|||||
$\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

|improve this answer|||||
$\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

|improve this answer|||||
$\endgroup$

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