1
$\begingroup$

Im trying to plot a horizontal strip in the (x,y)-plane with -1 < y < 1. I achieved this:

RegionPlot[
   y^2 <= 1, 
   {x, -2, 2}, 
   {y, -2, 2}, 
   Frame -> False, 
   BoundaryStyle -> Directive[Thickness[Medium], Dashed], 
   Axes -> True,
   AxesOrigin -> {0, 0}
]

enter image description here

As you can see I used dashed lines for the boundary. However mathematica draws this dashed line also at the left and right boundaries but theoretically my set is unbounded to the left and right. I would like to keep the lines on the top and on the bottm, but loosing them left and right.

$\endgroup$
  • $\begingroup$ Not a great idea, but reducing horizontal PlotRange to PlotRange -> {{-1.99,1.99},{-2,2}} cutts off left/right border. $\endgroup$ – Alx Nov 6 '19 at 12:49
3
$\begingroup$
RegionPlot[y^2 <= 1, {x, -2, 2}, {y, -2, 2}, 
  Frame -> False, 
  MeshFunctions -> {#2 &}, 
  Mesh -> {{-1, 1}}, 
  MeshStyle -> Dashed, 
  BoundaryStyle -> None, 
  Axes -> True, 
  AxesOrigin -> {0, 0}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ This seems to work for this example. Plotting the unit circle will end up having no dashed lines at all. $\endgroup$ – Arjihad Nov 6 '19 at 13:15
  • $\begingroup$ @Arjihad, the combination MeshFunctions -> {#2 &} and ` Mesh -> {{-1, 1}}` works for the specific case in your post. It does not work for all predicates in the first argument of RegionPlot. You need to make changes to the MeshFunctions and Mesh option values based on the region in the first argument of RegionPlot. $\endgroup$ – kglr Nov 6 '19 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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