3
$\begingroup$

I want to fill the region between two straight lines without displaying the region boundaries. How can it be done?

ContourPlot[{x == 2, x == 4}, {x, -2, 8}, {y, -2, 6}]

$\endgroup$

3 Answers 3

5
$\begingroup$

Use BoundaryStyle -> None as shown in the documentation of RegionPlot:

RegionPlot[2 <= x <= 4, {x, -2, 8}, {y, -2, 6}, BoundaryStyle -> None]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, @Roman. It's working. $\endgroup$ Oct 3, 2022 at 8:53
  • $\begingroup$ Just saw your answer after I updated. $\endgroup$
    – Nasser
    Oct 3, 2022 at 8:59
3
$\begingroup$

is this what you mean?

p1 = ContourPlot[{x == 2, x == 4}, {x, -2, 8}, {y, -2, 6}];
r = ImplicitRegion[2 < x < 4 && -2 < y < 6, {x, y}];
p2 = RegionPlot[r];
Show[p1, p2]

Mathematica graphics

Update

In this case, just plot the region directly. No need for ContourPlot at all to be there.

r = ImplicitRegion[2 < x < 4 && -2 < y < 6, {x, y}];
RegionPlot[r, BoundaryStyle -> None, 
 PlotRange -> {{-2, 8}, Automatic}]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Thanks, @Nasser for your answer. You are almost close. I just don't want the border lines surrounding the region. $\endgroup$ Oct 3, 2022 at 8:50
  • $\begingroup$ @SahabubJahedi fyi, updated $\endgroup$
    – Nasser
    Oct 3, 2022 at 8:59
  • $\begingroup$ Thanks, @Nasser, it's working. $\endgroup$ Oct 3, 2022 at 12:05
2
$\begingroup$
c := RandomInteger[{-100, 100}];

RegionPlot[RegionIntersection[
  HalfPlane[{{2, c}, {2, c}}, {1, 0}]
  , HalfPlane[{{4, c}, {4, c}}, {-1, 0}]
  ]
 , Frame -> True
 , BoundaryStyle -> None
 , PlotRange -> { {-2, 8}, {-2, 6}}
 ]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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